问题
I'm trying to configure wildfly which is running on localhost to send email but I'm failing miserably.
I've read a bunch of tutorial where they use gmail to send email but this require SSL, and the server is running with a self signed certificate so that doesn't work. One thing I don't understand is if I 've to use an smtp server like gmail or if wildfly has one integrated and if I can use it to send emails.
<subsystem xmlns="urn:jboss:domain:mail:2.0">
<mail-session jndi-name="java:jboss/mail/Default">
<smtp-server outbound-socket-binding-ref="mail-smtp">
</smtp-server>
</mail-session>
</subsystem>
...
<outbound-socket-binding name="mail-smtp">
<remote-destination host="localhost" port="25"/>
</outbound-socket-binding>
java :
@Resource(mappedName = "java:jboss/mail/Default")
private Session mailSession;
public void sendVerifEmail() {
try {
MimeMessage m = new MimeMessage(mailSession);
Address from = new InternetAddress("mymail@gmail.com");
Address[] to = new InternetAddress[] {new InternetAddress(user.getEmail()) };
m.setFrom(from);
m.setRecipients(Message.RecipientType.TO, to);
m.setSubject("registration");
m.setSentDate(new java.util.Date());
m.setContent("Mail sent from JBoss AS 7","text/plain");
Transport.send(m);
System.out.println("Mail sent!");
}
catch (javax.mail.MessagingException e)
{
e.printStackTrace();
}
}
回答1:
I thought I couldn't use gmail because I had an error when trying. It was actually my antivirus that didn't enable it. So disabling my antivirus solved the issue.
来源:https://stackoverflow.com/questions/37397274/send-email-wildfly-localhost