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

其他的包都是常用的.

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0