Error "550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain"

Viewed 1744

I use javamail to send email to a customer email address and has error :

com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.54 SMTP; Unable to relay recipient in non-accepted domain 

The code is below:

String to = "customer@customer.COM";// change accordingly
String from = "email@mycompany.com";
String host = "mail.mycompany.com";// or IP address

// Get the session object
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", "10.10.14.3");
properties.setProperty("mail.transport.protocol", "smtp");
properties.setProperty("mail.smtp.port", "25");// 
// Session session = Session.getDefaultInstance(properties);
Session session = Session.getInstance(properties, new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication("customer_service@mycompany.com", "Passat2020..");
        }
});
// compose the message
try {
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject("Ping");
    message.setText("Hello, this is example of sending email  ");
    // Send message
    Transport.send(message);
    System.out.println("message sent successfully....");
} catch (MessagingException mex) {
    mex.printStackTrace();
}

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.

0 Answers
Related