Send email wildfly localhost

不打扰是莪最后的温柔 提交于 2020-12-07 06:57:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!