我正在使用 apace 通用邮件 API 来发送 html 电子邮件。以下是我的代码。
public void sendHTMLMail(String to, String subject, String message , String from) throws EmailException
{
HtmlEmail email = new HtmlEmail();
email.setHostName(SMTP_HOST_NAME);
email.addTo(to);
email.setFrom(from, "just-flick");
email.setSubject(subject);
email.setSmtpPort(25);
email.setHtmlMsg(message);
email.setTextMsg("Your email client does not support HTML messages");
email.send();
}
但是在运行程序时我收到以下错误。
Exception in thread "main" org.apache.commons.mail.EmailException: Sending the e
mail to the following server failed : mail.just-flick.com:25
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
at org.apache.commons.mail.Email.send(Email.java:1267)
at bseller.mail.SendMail.sendHTMLMail(SendMail.java:105)
at bseller.mail.SendMail.main(SendMail.java:31)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invali
d HELO name (See RFC2821 4.1.1.1)
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
at javax.mail.Transport.send0(Transport.java:169)
at javax.mail.Transport.send(Transport.java:98)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
... 3 more
请帮我配置这个问题。
谢谢
我遇到了同样的问题,当我传递客户端主机的名称时,一切都变得正常 我在我的代码中添加了这一行:
props.put("mail.smtp.localhost", client or host name which connect to mail server);
祝你好运:)
这应该由邮件服务器的管理员处理,而不是由您处理。与告诉您连接到该邮件服务器的人交谈。
也许这会有所帮助:
email.getMailSession().getProperties().setProperty("mail.smtp.localhost", "www.example.com");
当然,请将 www.example.com 替换为您发送邮件的主机的域名。
但是,正如 David Schwartz 所写,您的邮件配置也不完美。目前,我们不再向端口 25 提交邮件。端口 587 用于提交,该端口的规则更宽松,但如果您的 IP 地址不在白名单中,可能需要验证您的身份。请点击 pst 在他的评论中给出的链接。
奇怪的是,JavaMail 单独工作,而 Apache Commons Email 却不行,因为我猜 Commons Email 也使用了 JavaMail。这可能表明某处存在错误,但需要进一步调查。
您的问题之一是您不知道您发送的确切 HELO 名称。以下代码可能有助于确定它,否则请致电您的邮件管理员(特别是因为他可能会在端口 587 上为您提供建议)。
email.getMailSession().setDebug(true);
我遇到了同样的错误,启用以下属性后已修复:
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
我将问题解决为: 如果发件人电子邮件地址的服务器部分是 xyz.com 例如([email protected]) 然后添加这个属性
props.put("mail.smtp.localhost", "xyz.com");
与我完美合作。