利用javamail 发送gmail邮件

可以使用javamail访问gmail进行邮件的收发。

private void configMailSmtp() { createMimeMessage(); m_Props.put("mail.smtp.host", m_SmtpConf.getAddr()); m_Props.put("mail.smtp.port", m_SmtpConf.getPort()); m_Props.put("mail.smtp.starttls.enable", "true"); m_Props.put("mail.smtp.auth", m_SmtpConf.getAuth()); Session mailSession = Session.getInstance(m_Props, null); try { if (m_SmtpConf.getIsGmail()) { m_Transport = mailSession.getTransport("smtps"); } else { m_Transport = mailSession.getTransport("smtp"); } m_Transport.connect((String) m_Props.get("mail.smtp.host"), m_SmtpConf.getUser(), m_SmtpConf.getPwd()); } catch (NoSuchProviderException e) { e.printStackTrace(); } catch (MessagingException e1) { e1.printStackTrace(); } }

需要将"smtp"修改为Transport t = session.getTransport("smtps");

参考javamail的FAQ.

http://www.oracle.com/technetwork/java/faq-135477.html

 

你可能感兴趣的:(利用javamail 发送gmail邮件)