'How to avoid email error (550 5.7.1 Command rejected) with Wildfly 8.1
I'm trying to send an email invoked from code.
@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);
}
}
My Wildfly 8.1 Server is configured as follows:
<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>
The socket outbound like this:
<outbound-socket-binding name="mail-smtp">
<remote-destination host="mail.doe.com" port="25"/>
<outbound-socket-binding>
The reported error is
(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
As in the example I try to send an email from my account [email protected] to [email protected]. Not to another domain.
On startup, wildfly does not report any errors with this configuration.
[org.jboss.as.mail.extension] (MSC service thread 1-5) L:136 JBAS015400: Bound mail session [java:jboss/mail/Default]
Any clue why that fails? In general I wonder why Java-Mail behaves not like a regular mail client.
Solution 1:[1]
Noting is wrong with your configuration or javamail implementation. Just mail server is rejecting commands from you/your sever/... There are many reason why mail server would do this, but in most cases all are related to preventing spam.
see related threads on SO about this as wel, and they are all related to mail server configuration.
for more see:
https://serverfault.com/questions/540159/remote-host-said-550-5-7-1-message-content-rejected
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |