发送邮件已经弄好了,秉着开源的精神,我与大家分享一下,或许能帮助到有需要的朋友。
说明:
工具包直接下载后本地可跑,配置好参数在本地可发送邮件。
制作精美的邮件模板(HTML)发送简历的时候可以更加漂亮或许能给你拉票 哈哈。
废话不多说。解释一下我这些个类。
核心类主要有:
ConfigPropertiesHelper 邮件发送配置文件相关类。
FilesTools 文件读取工具类
GroupsSendMail 邮件群发类
ServiceException 异常处理
Myth 邮件发送线程池
SendMailHelper 邮件发送相关辅助类
SendMailMain 发送邮件类 main方法可以放在这里测试(不涉及多线程)
假设要多线程发送邮件,在条件允许的情况下,你可以修改一下多线程那个类,然后可以测试。
发送邮件测试主要是个大问题,抛砖引玉各位可以给点建议
ConfigPropertiesHelper中这里读取配置文件,要是报错,大家注意修改这个位置。
static {
configs = new Properties();
try {
String path = helper.getClass().toString();
URL url = helper.getClass().getResource(
"../../MailConfig.properties");
configs.load(url.openStream());
} catch (Exception e) {
e.printStackTrace();
try {
throw new ServiceException(e.getMessage());
} catch (ServiceException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
SendMailMain 直接执行这个类开始发送
public static void main(String[] arg){
SendMailMain t = new SendMailMain();
t.setToAddress(new String[]{"xxxx@qq.com","xxxx@163.com"});
t.setMailSubject("我在家自己测");
t.setMailContent("实施事实");
t.setSysPerson("我日起火焰");
t.sendMail();
}
MailConfig.properties
配置文件
dateformat=yyyy-MM-dd HH:mm
attachpath=
smtp=
pop3=
pop3port=
user=
pass=
sysemail=
sysname=
这些参数,只要你在玩邮件,你应该都知道的。
好啦,其他的附件中看。多线程那些我就不传啦,感觉写得不好。并且有些BUG