2011-12-17 131 views
2

我使用apace常用郵件API發送html電子郵件。以下是我的代碼。550訪問被拒絕 - 無效的HELO名稱

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 

請幫我配置這個問題。

謝謝

+2

你沒有正確地問服務器:( – 2011-12-17 04:37:34

+0

嗨感謝您的回答,請幫我這個。我是新的SMTP服務器配置。 – Pedantic 2011-12-17 04:50:14

回答

1

這應該由郵件服務器的管理員來處理,而不是由您來處理。與任何告訴你連接到該郵件服務器的人通話。

1

也許這將幫助:

 
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); 
3

我面臨同樣的問題,當我通過客戶端主機的一切的名字成爲確定 我在我的代碼中加入這一行:

props.put("mail.smtp.localhost", client or host name which connect to mail server); 

好運:)