SMTP Mail Sending Issue : com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay

匿名 (未验证) 提交于 2019-12-03 02:43:01

问题:

I am trying to send mail from Java. If i will send mail to same SMTP it working fine. If i will send mail to outside SMTP means like Gmail, Yahoo etc. it'as shows error like,

[com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay][1]

ERROR :

SimpleEmail Start javax.mail.SendFailedException: Invalid Addresses;   nested exception is:     com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay  Mail Send Successfully     at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:2064)     at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1286)     at javax.mail.Transport.send0(Transport.java:255)     at javax.mail.Transport.send(Transport.java:124)     at com.nirav.java.project.demo.JavaMailSend.sendEmail(JavaMailSend.java:26)     at com.nirav.java.project.demo.NewSimpleMail.main(NewSimpleMail.java:34) Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay      at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1917)     ... 5 more 

Code For Mail Sending :

try {             System.out.println("SimpleEmail Start");              String smtpHostServer = "XX.XX.XX.XXX";             final String toEmail = "XXXXXXXXXX@XXX.XXX";             final String fromEmail = "XXXXXXXXXX@XXX.XXX";             final String password = "XXXXXXXXXXXX";              Properties props = System.getProperties();              props.put("mail.smtp.host", smtpHostServer);             props.put("mail.smtp.port", "25"); //If other then              Session session = Session.getInstance(props, new javax.mail.Authenticator() {                 protected PasswordAuthentication getPasswordAuthentication() {                     return new PasswordAuthentication(fromEmail, password);                 }             });             //Session session = Session.getInstance(props, null);            MimeMessage message = new MimeMessage(session);            message.addHeader("Content-type", "text/HTML; charset=UTF-8");           message.addHeader("format", "flowed");           message.addHeader("Content-Transfer-Encoding", "8bit");           message.setFrom(new InternetAddress("XXXXXX@XXX.XXX", "NoReply-JD"));           message.setReplyTo(InternetAddress.parse("XXXXXXXXX@XXX.XXX", false));           message.setSubject(subject, "UTF-8");           message.setText(body, "UTF-8");           message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail, false));           Transport.send(message);              System.out.println("Mail Send Successfully");         } catch (Exception e) {             e.printStackTrace();         } 

Please help me. Thnaks.

回答1:

Originaly I was about to post this as comment, but it's too long.

Error is quite obvious, you are not allowed to use given SMTP server as relay. (What are SMPT relays?)

There are couple of reasons why this can happen:

  • You are not authenticated (need to login before sending)

  • Recipient is not in list of domains allowed to relay to

  • IP address from which you are connecting is not in white list (aka mynetworks in postfix context)

without providing more info (which SMTP server you are using, where are you sending mail, are you authenticated), I guess nobody will help you.

5.7.1 status code from IANA registry

The sender is not authorized to send to the destination. This can be the result of per-host or per-recipient filtering. This memo does not discuss the merits of any such filtering, but provides a mechanism to report such. This is useful only as a permanent error.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!