2014-05-13 20 views
0

我有了2種方法MailSender類:爲什麼Java MailSender不識別目標電子郵件?

private Session createSmtpSession(final String fromEmail, final String fromEmailPassword) { 
    final Properties props = new Properties(); 
    props.setProperty ("mail.host", "smtp.gmail.com"); 
    props.setProperty("mail.smtp.auth", "true"); 
    props.setProperty("mail.smtp.port", "" + 587); 
    props.setProperty("mail.smtp.starttls.enable", "true"); 
    props.setProperty ("mail.transport.protocol", "smtp"); 


    return Session.getDefaultInstance(props, new javax.mail.Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(fromEmail, fromEmailPassword); 
     } 
    }); 
} 

public void sendEmail(String subject, String fromEmail, String fromEmailPassword, String content, String toEmail){ 
    Session mailSession = createSmtpSession(fromEmail, fromEmailPassword); 
    mailSession.setDebug (true); 

    try { 
     Transport transport = mailSession.getTransport(); 

     MimeMessage message = new MimeMessage (mailSession); 

     message.setSubject (subject); 
     message.setFrom (new InternetAddress (fromEmail)); 
     message.setContent (content, "text/html"); 
     message.addRecipient (Message.RecipientType.TO, new InternetAddress (toEmail)); 

     transport.connect(); 
     transport.sendMessage (message, message.getRecipients (Message.RecipientType.TO)); 
    } 
    catch (MessagingException e) { 
     System.err.println("Cannot Send email"); 
     e.printStackTrace(); 
    } 
} 

確定,上面的代碼的工作方式是這樣的:

我的個人Gmail [email protected] &如果我要發送味精目的地電子郵件像[email protected] [email protected],然後我需要調用sendEmail(subject, "[email protected]", fromEmailPassword, content, "[email protected]");

但最近我買了VPS從Godaddy的&我使用GoDaddy的電子郵件([email protected]),所以我想送SMG像AA目的地電子郵件@ xyz.com從[email protected],然後我需要調用sendEmail(subject, "[email protected]", fromEmailPassword, content, "[email protected]");

但是我使用端口25 遇到錯誤COS Godaddy的所以我改變了代碼createSmtpSession如下:

props.setProperty ("mail.host", "smtp.mydomain.com"); 
props.setProperty("mail.smtp.port", "" + 25); 

然而,這個時候,我還有其他的問題

DEBUG SMTP: Sending failed because of invalid destination addresses 
RSET 
250 2.0.0 OK 
DEBUG SMTP: MessagingException while sending, THROW: 
javax.mail.SendFailedException: Invalid Addresses; 
    nested exception is: 
    com.sun.mail.smtp.SMTPAddressFailedException: 550 5.1.1 <[email protected]> Recipient not found. <http://x.co/irbounce> 

顯然[email protected]實際上是存在的,但爲什麼錯誤說Recipient not found.

SO如何解決這個問題?

+0

你應該打開GoDaddy的支持票。 – jdiver

+0

您需要使用GoDaddy支持團隊檢查此問題。 – Forhad

+0

我需要告訴他們什麼?他們中的許多人不知道Java – Kiti

回答

0

我需要看看在Godaddy的電子郵件&的發送(SMTP)服務器(如smtpout.secureserver.net)現在它工作正常

props.setProperty ("mail.transport.protocol", "smtps"); 
    props.setProperty ("mail.smtps.host", "smtpout.secureserver.net"); 
    props.setProperty("mail.smtps.auth", "true"); 
    props.setProperty("mail.smtps.port", "" + 465);