java发送邮件方法
文章目录
package com.imgsys.ssh.util;
import org.apache.commons.mail.SimpleEmail;
public class mySendMail {
public String send(String toEmail,String emailTitle,String emailValue) {
String returnStr="";
try {
if(emailTitle==null || "".equals(emailTitle)){
return "标题不能为空";
}
SimpleEmail email = new SimpleEmail();
email.setTLS(true);
email.setHostName("smtp.qq.com");
email.setAuthentication("
你的qq邮箱@qq.com", "qq邮箱独立密码"); // 用户名和密码
email.addTo(toEmail); // 接收方
email.setFrom("你的qq邮箱@qq.com"); // 发送方
email.setSubject(emailTitle); // 标题
email.setMsg(emailValue); // 内容
email.send();
returnStr="发送成功,密码已发送至邮箱!请即使查收!";
} catch (Exception e) {
returnStr="发送失败,请检查邮箱是否被注册。信息是否正确。";
//e.printStackTrace();
}
return returnStr;
}
}
有用到的jar包: 链接: https://pan.baidu.com/s/11hVA1hBrikNE2QnoP5ybQg 提取码: zcjw
其他的包都是常用的.
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册⭐️ Admin快速开发: https://show.cool-admin.com/
赞 0⭐️ 官方文档: https://cool-js.com
赞 0⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld
赞 0