此文章只是基础代码,需要自己深层次的封装,适用于初次开发工作者
1代码
private static final String from="";//163邮件的账号
private static final String host = "smtp.163.com";
private static final String password = "";//163邮箱的授权码,下面会详细描述怎么开通【注意,不是密码】
public static boolean sendMail(String to, String content){
Properties prop = new Properties();
prop.setProperty("mail.host", host);
prop.setProperty("mail.smtp.auth", "true");
prop.setProperty("mail.transport.protocol", "smtp");
/* prop.put("mail.smtp.ssl.enable", true);*/
// 开启SSL加密,否则会失败
try {
MailSSLSocketFactory sf = new MailSSLSocketFactory();
sf.setTrustAllHosts(true);<