简体   繁体   中英

setup email connection in java

I am trying to make connection to the email server using property files and session store value. and all the parameters are given dynamically. this is what i'm trying

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

Even if i am giving the correct email and password, the connection is not setting up.

please do the needful help.

Thanks in advance.

Couple of ideas:

  1. make sure the email server does not require pop3 login first.
  2. make sure port is open in firewall

Do you get any exceptions during your tries?

Does it throw an exception or it just doesn't work? I am using gmail for sending emails and I used something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM