【问题标题】:How to avoid email error (550 5.7.1 Command rejected) with Wildfly 8.1如何使用 Wildfly 8.1 避免电子邮件错误(550 5.7.1 命令被拒绝)
【发布时间】:2014-12-30 09:56:13
【问题描述】:

我正在尝试发送一封从代码调用的电子邮件。

@Stateless
public class MailBean {

    private static Logger LOGGER = Logger.getLogger(MailBean.class);
    private String EMAIL_REGEX = "^(([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5}){1,25})+([;.](([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5}){1,25})+)*$";

    @Resource(name = "java:jboss/mail/Default")
    private Session mailSession;

    @Asynchronous
    public void send(String addresses, String topic, String textMessage) {

        try {
            MimeMessage message = new MimeMessage(mailSession);
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addresses));
            message.setSubject(topic);
            message.setText(textMessage);

            Transport transport = mailSession.getTransport();
            transport.connect();
            transport.send(message);

        } catch (MessagingException ex) {
            LOGGER.error("Cannot send mail to " + addresses + ". Error: " + ex.getMessage(), ex);
        }
    }

    public boolean isValidEmailAddress(String email) {
        if (email == null)
            return false;
        else
            return email.matches(EMAIL_REGEX);
    }
}

我的 Wildfly 8.1 服务器配置如下:

<subsystem xmlns="urn:jboss:domain:mail:2.0">
    <mail-session name="mail-session-default" jndi-name="java:jboss/mail/Default">
                <smtp-server outbound-socket-binding-ref="mail-smtp" 
                ssl="false"
                username="john@doe.com" 
                password="****"/>

    </mail-session>
</subsystem>

socket outbound 是这样的:

<outbound-socket-binding name="mail-smtp">
    <remote-destination host="mail.doe.com" port="25"/>
<outbound-socket-binding>

报告的错误是

(EJB default - 2) L:38 Cannot send mail to jane@doe.com. Error: 550 5.7.1 Command rejected
: com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Command rejected

在示例中,我尝试从我的帐户 john@doe.com 向 jane@doe.com 发送电子邮件。不是到另一个域。

在启动时,wildfly 不会报告此配置的任何错误。

[org.jboss.as.mail.extension] (MSC service thread 1-5) L:136 JBAS015400: Bound mail session [java:jboss/mail/Default]

任何线索为什么会失败?一般来说,我想知道为什么 Java-Mail 的行为不像普通的邮件客户端。

【问题讨论】:

    标签: wildfly wildfly-8


    【解决方案1】:

    请注意您的配置或 javamail 实现有误。 只是邮件服务器正在拒绝来自您/您的服务器/...的命令 邮件服务器这样做的原因有很多,但大多数情况下都与防止垃圾邮件有关。

    也可以在 SO 上查看相关线程,它们都与邮件服务器配置有关。

    更多请看:

    https://serverfault.com/questions/453638/plesk-postfix-smtp-550-5-7-1-command-rejected-for-one-external-sender

    https://serverfault.com/questions/540159/remote-host-said-550-5-7-1-message-content-rejected

    【讨论】:

      猜你喜欢
      • 2018-08-02
      • 2015-03-11
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 2016-10-16
      • 1970-01-01
      相关资源
      最近更新 更多