使用MailServer自定义邮件服务器java发送邮件-----之一

今天使用了MailServer自定义邮件服务器和Foxmail进行代码发送邮件测试。具体邮箱服务器和foxmail的安装步骤非常简单就不进行记录了,安装包啥的可以直接到官网进行下载或者联系我邮箱。

public class SendEmailUtils {

public static void main(String[] args) {
send("user01@cupid.com", ProduceUtils.getCode() + ProduceUtils.getCode());
}

public static void send(String toMail , String code){

try {
Properties props = new Properties();
//由于是本地邮箱服务器就不需要填写了
//props.setProperty("host", "smtp");
EmailEntity entity = new EmailEntity("user05@cupid.com", "123");
Session session = Session.getInstance(props, entity);

//创建一个邮件对象
Message message = new MimeMessage(session);
//设置发件人
message.setFrom(new InternetAddress("user05@cupid.com"));
//设置收件人
message.addRecipient(RecipientType.TO, new InternetAddress(toMail));
//设置主题
message.setSubject("来自于丘比特求爱网的注册验证消息");
//设置邮件正文
message.setContent("<h1>来自于丘比特求爱网的注册验证消息,请点击以下链接</h1><h3><a href='http://localhost:8080/JMailDemo/CheckMailServlet?code="+code+"'>http://localhost:8080/JMailDemo/CheckMailServlet?code="+ code +"</a></h3>" , "text/html;charset=UTF-8");

//发送邮件
Transport.send(message);

} catch (MessagingException e) {
e.printStackTrace();
}


}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值