我正在尝试使用javamail api发送邮件但得到450 4.7.1客户端主机拒绝错误

问题描述 投票:-1回答:2
DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.server.com", port 25, isSSL false
220 smtp.server.com ESMTP Postfix (Ubuntu)
DEBUG SMTP: connected to host "smtp.server.com", port: 25

EHLO MYPC
250-smtp.server.com
250-PIPELINING
250-SIZE 20480000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "20480000"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
450 4.7.1 Client host rejected: cannot find your hostname, [172.17.9.70]
DEBUG SMTP: Valid Unsent Addresses
DEBUG SMTP:   [email protected]
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 2.0.0 Ok
javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
        com.sun.mail.smtp.SMTPAddressFailedException: 450 4.7.1 Client host rejected: cannot find your hostname, [172.17.9.70]

        at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1835)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1098)
        at javax.mail.Transport.send0(Transport.java:195)
        at javax.mail.Transport.send(Transport.java:124)
        at defaultsrc.SendMail.main(SendMail.java:71)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 450 4.7.1 Client host rejected: cannot find your hostname, [172.17.9.70]

        at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1700)
        ... 9 more
QUIT
221 2.0.0 Bye

上面的ip 172.17.9.70是我的计算机局域网IP,MYPC是我的主机名。它似乎比邮件服务器成功连接。但不知道为什么它说“客户主机拒绝”。邮件服务器不需要任何身份验证并使用端口25.任何人都可以帮助我?

java
2个回答
0
投票

我会回应其他评论者,并建议在服务器故障上提出这个问题可能会更好......但我的猜测是这是一个DNS问题。 MX正在从您的IP地址查找您的主机名而没有找到任何内容(“找不到您的主机名”)。见https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS


0
投票

我遇到了同样的错误,来到这里寻找解决方案。经过一番挖掘后,我想出了以下代码,这在我的案例中有效:

String recipient = "[email protected]";
String sender = "[email protected]";
Session session = Session.getDefaultInstance(new Properties());
try {
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(sender));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject("TEST SUBJECT");
    message.setText("TEST BODY");
    Transport transport = session.getTransport("smtp");
    transport.connect("<smtp.host>", "<smtp.user>", "<smtp.password>");
    message.saveChanges();
    transport.sendMessage(message, new Address[]{new InternetAddress(recipient)});
    Transport.send(message);
} catch (MessagingException mex) {
    mex.printStackTrace();
}

也许有人会发现它很有用:)

© www.soinside.com 2019 - 2024. All rights reserved.