发送电子邮件wildfly localhost [英] Send email wildfly localhost

查看:176
本文介绍了发送电子邮件wildfly localhost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置在本地主机上运行的wildfly以发送电子邮件,但我失败了。

I'm trying to configure wildfly which is running on localhost to send email but I'm failing miserably.

我读了一堆教程,他们使用gmail发送电子邮件,但这需要SSL,并且服务器正在使用自签名证书运行,因此无法正常工作。我不明白的一件事是,如果我必须使用像gmail这样的smtp服务器,或者wildfly是否集成了一个,并且可以使用它来发送电子邮件。

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();
    }

}

推荐答案

我以为我无法使用gmail,因为尝试时出现错误。实际上是我的防病毒软件没有启用它。因此,禁用我的防病毒软件解决了该问题。

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.

这篇关于发送电子邮件wildfly localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆