java mail 抄送多用户,Java Mail 发送多人、抄送多人,附件上传 邮件发送效能

package com.tobacco.ermsuite.interfaces.mail;

import javax.mail.Authenticator;

import javax.mail.PasswordAuthentication;

public class MailAuthenticator extends Authenticator {

String userName = null;

String password = null;

public MailAuthenticator() {

}

public MailAuthenticator(String username, String password) {

this.userName = username;

this.password = password;

}

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(userName, password);

}

}

package com.tobacco.ermsuite.interfaces.mail;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

public class MailFactory {

private static MailProperties defaultProp;

static {

defaultProp = new MailProperties();

defaultProp.setMailServerHost("smtp.163.com");

defaultProp.setMailServerPort("25");

defaultProp.setValidate(true);

defaultProp.setUserName("oops22");

defaultProp.setPassword("wen789789");// 您的邮箱密码

}

public static Map sendMail(String subject, String content, List toAddress,

List ccAddress,Map attachFile) {

Map resultMap = new HashMap();

if (toAddress != null && toAddress.size() > 0) {

defaultProp.setToAddress(toAddress);

defaultProp.setCcAddress(ccAddress);

defaultProp.setAttachFile(attachFile);

defaultProp.setSubject(subject);

defaultProp.setContent(content);

resultMap = MailUtil.sendHtmlMail(defaultProp);

} else {

resultMap.put("state", "failed");

resultMap.put("message", "邮件发送失败!错误原因:收件人为空");

}

return resultMap;

}

public static Map sendMail(String subject, String content, List toAddress,Map attachFile) {

Map resultMap = sendMail(subject, content, toAddress, null,attachFile);

return resultMap;

}

}

package com.tobacco.ermsuite.interfaces.mail;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Properties;

public class MailProperties {

// 发送邮件的服务器的IP和端口

private String mailServerHost;

private String mailServerPort = "25";

// 邮件发送者的地址

private String fromAddress;

// 邮件接收者的地址

private List toAddress;

// 抄送的地址

private List ccAddress;

// 登陆邮件发送服务器的用户名和密码

private String userName;

private String password;

// 是否需要身份验

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值