如何使用Wildfly 8.1避免电子邮件错误(550 5.7.1命令被拒绝)

问题描述 投票:2回答:1

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

@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="[email protected]" 
                password="****"/>

    </mail-session>
</subsystem>

套接字出站如下:

<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 [email protected]. Error: 550 5.7.1 Command rejected
: com.sun.mail.smtp.SMTPSendFailedException: 550 5.7.1 Command rejected

在示例中,我尝试从我的帐户[email protected]发送电子邮件至[email protected]。不是到另一个域名。

启动时,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个回答
0
投票

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

请参阅有关此问题的相关主题,并且它们都与邮件服务器配置有关。

了解更多:

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

© www.soinside.com 2019 - 2024. All rights reserved.