2016-04-25 89 views
0

我有託管帳戶,以我公司的Gmail電子郵件,我試圖從該帳戶在java中發送郵件,但現在面臨以下錯誤:發送使用特定的Gmail從Java的電子郵件accont

javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsF 
534-5.7.14 i7ZvgRt2ia4HE_atVycPueORguLHg4yVG6hw_JGdAgbyUkBfJySVDR_XvkzLZzQp88F-UN 
534-5.7.14 aoGU0uN-UBUR91zW7jsbzeq8Ojr6FEjFQcpsVKpv9GLaUPY3ee-pUk3Y6eNABFeA8DgDlu 
534-5.7.14 fNDQwLg_R1I5-veyWJ8qE73R833F8PHWFuRanCjTkyPjQogqO-VrBG6omrZHsP3I-8Wphr 
534-5.7.14 AjvaiqquhwnrUrmKjyk6RKaJnYaiA> Please log in via your web browser and 
534-5.7.14 then try again. 
534-5.7.14 Learn more at 
534 5.7.14 https://support.google.com/mail/answer/78754 w77sm17182835wmw.10 - gsmtp 

,這裏是屬性用我的代碼:

final String username = "[email protected]"; 
    final String password = "********"; 


    final String host = "smtp.gmail.com"; 
    final String port = "587"; 

    // Creating Properties object 
    Properties props = new Properties(); 
    // Defining properties 
    props.put("mail.smtp.host", host); 
    props.put("mail.transport.protocol", "smtp"); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.starttls.enable", "true"); 

    props.put("mail.user", username); 
    props.put("mail.password", password); 
    props.put("mail.port", port); 

    // Authorized the Session object. 
    Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() { 
     @Override 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(username, password); 
     } 
    }); 

所以要清楚,我的電子郵件是([email protected])和mycompany.com的電子郵件Gmail的託管。 如果我用Gmail電子郵件([email protected])替換我的電子郵件,它可以正常工作,那麼這裏有什麼問題以及如何解決。

+0

許多下面的建議是錯誤的,只是使代碼更復雜。查看[常見的JavaMail錯誤]列表(http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes)。你按照錯誤消息的指示,[你的瀏覽器登錄](https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsFi7ZvgRt2ia4HE_atVycPueORguLHg4yVG6hw_JGdAgbyUkBfJySVDR_XvkzLZzQp88F-UNaoGU0uN-UBUR91zW7jsbzeq8Ojr6FEjFQcpsVKpv9GLaUPY3ee-pUk3Y6eNABFeA8DgDlufNDQwLg_R1I5-veyWJ8qE73R833F8PHWFuRanCjTkyPjQogqO-VrBG6omrZHsP3I-8WphrAjvaiqquhwnrUrmKjyk6RKaJnYaiA )? –

+0

是的,我做了,但沒有發生任何事 –

回答

0

我覺得你的問題性質mail.smtp.portmail.smtp.socketFactory.port

請註明如果不和更改端口號應罰款給你。

試試這個屬性集...您的代碼必須工作(從我的跑步項目添加一個工作代碼)

  v_objProperties = new Properties(); 
      v_objProperties.put("mail.smtp.host","smtp.gmail.com"); 
      v_objProperties.put("mail.smtp.auth", "true"); 
      v_objProperties.put("mail.debug", "false"); 
      v_objProperties.put("mail.smtp.port",25); 
      v_objProperties.put("mail.smtp.socketFactory.port",25); 
      v_objProperties.put("mail.smtp.starttls.enable", "true"); 
      v_objProperties.put("mail.transport.protocol", "smtp"); 
      v_objSession = Session.getInstance(v_objProperties, new Authenticator() { 
       @Override 
       protected PasswordAuthentication getPasswordAuthentication() { 
        return new PasswordAuthentication("[email protected]", "*********"); 
       } 
      }); 
+0

我仍然面臨同樣的錯誤 –

0

起初,修正類似如下props.put("mail.port", port);

props.put("mail.smtp.port", port); 

驗證碼對於host,您的編碼僅適用於@gmail.com的一部分。它不會運行自己的域名Gmail服務(E.g; ****@abc.com)。主要使用。這就是爲什麼,需要通過authroize person/account配置郵件設置。

REF:SSL using in Javamkyoung

相關問題