SMTP邮件发送问题:com.sun.mail.smtp.SMTPAddressFailedException:550 5.7.1无法中继 [英] SMTP Mail Sending Issue : com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay

查看:3473
本文介绍了SMTP邮件发送问题:com.sun.mail.smtp.SMTPAddressFailedException:550 5.7.1无法中继的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Java发送邮件。
如果我将邮件发送到同一个SMTP它工作正常。
如果我将邮件发送到外部SMTP意味着像Gmail,雅虎等那么显示错误喜欢,

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无法中继] [1]

错误:

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

邮件发送代码:

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();
        }

请帮助我。
Thnaks。

Please help me. Thnaks.

推荐答案

我原本即将发布此评论,但时间太长了。

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

错误很明显,不允许使用给定的SMTP服务器作为中继。 (什么是SMPT继电器?

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您连接的地址不在白名单中(在后缀上下文中也称为mynetworks)

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

但未提供更多信息(您正在使用哪个SMTP服务器,您在哪里发送邮件,是否经过身份验证),我想没有人会帮助您。

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来自IANA注册局的状态代码


发件人无权发送到目的地。这可以是每个主机或每个收件人筛选的结果
。本备忘录不会讨论任何此类过滤的优点,但提供了一种机制,以
报告此类。这仅作为永久性错误有用。

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.

这篇关于SMTP邮件发送问题:com.sun.mail.smtp.SMTPAddressFailedException:550 5.7.1无法中继的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆