簡體   English   中英

在Java中設置電子郵件連接

[英]setup email connection in java

我正在嘗試使用屬性文件和會話存儲值建立到電子郵件服務器的連接。 並且所有參數都是動態給出的。 這就是我正在嘗試的

  Properties props = System.getProperties();
  props.put("mail.smtp.auth", "true");
  props.put("mail.smtp.starttls.enable", "true");
  props.put("mail.smtp.host", emailHost);
  props.put("mail.smtp.port", "2525");
  Session sessions = Session.getDefaultInstance(props);
  Store store = sessions.getStore(emailAccType);
  store.connect(emailHost, emailId, emailPwd);

即使我提供了正確的電子郵件和密碼,也未建立連接。

請做必要的幫助。

提前致謝。

幾個想法:

  1. 確保電子郵件服務器不需要先登錄pop3。
  2. 確保端口在防火牆中打開

嘗試期間是否有任何例外情況?

它會引發異常還是無法正常工作? 我正在使用gmail發送電子郵件,並且我使用了以下方法:

Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(email, password);
        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM