title: Error "550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain"
body: <p>I use javamail to send email to a customer email address and has error :</p>
  <pre><code>com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain 
  </code></pre>
  <p>The code is below:</p>
  <pre><code>String to = &quot;customer@customer.COM&quot;;// change accordingly
  String from = &quot;email@mycompany.com&quot;;
  String host = &quot;mail.mycompany.com&quot;;// or IP address
  
  // Get the session object
  Properties properties = System.getProperties();
  properties.setProperty(&quot;mail.smtp.host&quot;, &quot;10.10.14.3&quot;);
  properties.setProperty(&quot;mail.transport.protocol&quot;, &quot;smtp&quot;);
  properties.setProperty(&quot;mail.smtp.port&quot;, &quot;25&quot;);// 
  // Session session = Session.getDefaultInstance(properties);
  Session session = Session.getInstance(properties, new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
           return new PasswordAuthentication(&quot;customer_service@mycompany.com&quot;, &quot;Passat2020..&quot;);
          }
  });
  // compose the message
  try {
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      message.setSubject(&quot;Ping&quot;);
      message.setText(&quot;Hello, this is example of sending email  &quot;);
      // Send message
      Transport.send(message);
      System.out.println(&quot;message sent successfully....&quot;);
  } catch (MessagingException mex) {
      mex.printStackTrace();
  }
  </code></pre>
  <p>If I send to customer using outlook it work. Sending to myaddress@mycompany.com instead with this code and it work too. So is this something wrong with the relay setting of smtp server?and if receiver and sender in same domain or in outlook, it will not use relay service?Thx.</p>