title: How to avoid email error (550 5.7.1 Command rejected) with Wildfly 8.1
body: <p>I'm trying to send an email invoked from code.</p>
  
  <pre><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);
      }
  }
  </code></pre>
  
  <p>My Wildfly 8.1 Server is configured as follows:</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:mail:2.0"&gt;
      &lt;mail-session name="mail-session-default" jndi-name="java:jboss/mail/Default"&gt;
                  &lt;smtp-server outbound-socket-binding-ref="mail-smtp" 
                  ssl="false"
                  username="john@doe.com" 
                  password="****"/&gt;
  
      &lt;/mail-session&gt;
  &lt;/subsystem&gt;
  </code></pre>
  
  <p>The socket outbound like this: </p>
  
  <pre><code>&lt;outbound-socket-binding name="mail-smtp"&gt;
      &lt;remote-destination host="mail.doe.com" port="25"/&gt;
  &lt;outbound-socket-binding&gt;
  </code></pre>
  
  <p>The reported error is </p>
  
  <pre><code>(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
  </code></pre>
  
  <p>As in the example I try to send an email from my account john@doe.com to jane@doe.com. Not to another domain.</p>
  
  <p>On startup, wildfly does not report any errors with this configuration.</p>
  
  <pre><code>[org.jboss.as.mail.extension] (MSC service thread 1-5) L:136 JBAS015400: Bound mail session [java:jboss/mail/Default]
  </code></pre>
  
  <p>Any clue why that fails? In general I wonder why Java-Mail behaves not like a regular mail client.</p>