java发送邮件工具类 发表于 2018-05-23 | 更新于: 2018-08-16 | 分类于 Java | | 阅读次数: 使用javamail实现发邮件的代码样例,可以自定发件人,或者匿名发送 12345678910111213141516171819202122232425262728293031323334353637383940414243package com.zhangzob.util;import lombok.Data;import lombok.extern.slf4j.Slf4j;import org.simplejavamail.email.Email;import org.simplejavamail.mailer.Mailer;import javax.mail.Message;import java.util.List;import java.util.Map;/** * Created by zhangzb on 17-2-10. */@Slf4j@Datapublic class SendEmailUtil { /** * @param map 要发送的消息 * @param toUser 收件人邮箱 */ public static void sendEmail(Map<String, List<String>> map, String toUser){ StringBuilder stringBuilder = new StringBuilder(); for(String value : map.keySet()){ stringBuilder.append(value); stringBuilder.append(":"); stringBuilder.append(map.get(value).toString()); stringBuilder.append("\n"); } Email email = new Email(); email.setFromAddress("apiTest", "[email protected]"); email.addRecipient("", toUser, Message.RecipientType.TO); email.setSubject("测试结果"); email.setText(stringBuilder.toString()); new Mailer("smtp.163.com", 25, "[email protected]", "yourPassword").sendMail(email); log.info("发送成功!"); }} 觉得有帮助就赞赏一下吧 赞赏 微信支付 支付宝 本文作者: zongbo.zhang 原始链接: https://zobgo.com/Java/java-send-mail-util.html 版权声明: 本站遵循CC BY-NC-SA 3.0 许可协议。