首页>代码>java servlet+mysql开发的学校官网+教务系统+图书馆系统,功能完善,供参考学习>/五道口科学研究院/MyUniversity/src/cn/com/dao/MailUtil.java
package cn.com.dao; import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; /** * 邮件工具类 */ public class MailUtil { /** * 发送邮件 * @param to 给谁发 * @param text 发送内容 */ public static void send_mail(String to,String text) throws MessagingException { //创建连接对象 连接到邮件服务器 Properties properties = new Properties(); //设置发送邮件的基本参数 //发送邮件服务器 properties.put("mail.smtp.host", "smtp.qq.com"); //发送端口 properties.put("mail.smtp.port", "25"); properties.put("mail.smtp.auth", "true"); //设置发送邮件的账号和密码 Session session = Session.getInstance(properties, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { //两个参数分别是发送邮件的账户和邮件客户端授权码 return new PasswordAuthentication("填发送邮件用的qq邮箱","邮件客户端授权码"); } }); //创建邮件对象 Message message = new MimeMessage(session); //设置发件人 message.setFrom(new InternetAddress("填发送邮件用的qq邮箱")); //设置收件人 message.setRecipient(Message.RecipientType.TO,new InternetAddress(to)); //设置主题 message.setSubject("五道口科学研究院身份验证"); //设置邮件正文 第二个参数是邮件发送的类型 message.setContent(text,"text/html;charset=UTF-8"); //发送一封邮件 Transport.send(message); } }

alive13gyp LV2
3月19日
huangzy LV12
2024年10月23日
3263394665 LV9
2023年11月29日
你爹正在加载中 LV4
2023年7月12日
全栈小白 LV35
2023年5月23日
ewan007 LV30
2023年2月20日
263648 LV7
2023年2月14日
stonewan LV10
2022年11月25日
485415187 LV6
2022年11月24日
bluesky2016 LV15
2022年7月6日

alive13gyp LV2
3月19日
微信网友_7398626323435520 LV3
2月25日
LoveSummer LV6
2024年10月31日
颜菜菜 LV2
2024年9月6日
janeqin LV1
2024年7月18日
TY0165 LV20
2024年6月24日
胡闹的番茄精 LV2
2024年6月17日
卢旯旯 LV4
2024年6月11日
jimodeai LV15
2024年5月5日
周青松197 LV3
2024年4月30日