java实现邮箱群发功能

发布时间:2023-10-18 点击:108
近来无事,在网上看了一些大牛文章,其中看到一篇比较好的,分享给大家!
下面是代码
邮箱实体
import java.io.serializable; / * 邮件实体类 */ public class mail implements serializable { / * 序列号 */ private static final long serialversionuid = -3562218214168975242l; / * 邮件编码s */ public static final string encodeing = “utf-8″; / * 服务器地址 */ private string host; / * 服务器端口号 */ private string portnumber; / * 发件人的邮箱 */ private string sender; / * 收件人的邮箱 */ private string receiver; / * 发件人昵称 */ private string name; / * 账号 */ private string username; / * 密码 */ private string password; / * 主题 */ private string subject; / * 信息(支持html) */ private string message; public string gethost() { return host; } public void sethost(string host) { this.host = host; } public string getsender() { return sender; } public string getportnumber() { return portnumber; } public void setportnumber(string portnumber) { this.portnumber = portnumber; } public void setsender(string sender) { this.sender = sender; } public string getreceiver() { return receiver; } public void setreceiver(string receiver) { this.receiver = receiver; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public string getsubject() { return subject; } public void setsubject(string subject) { this.subject = subject; } public string getmessage() { return message; } public void setmessage(string message) { this.message = message; } }工具类
import org.apache.commons.mail.emailexception; import org.apache.commons.mail.htmlemail; public class mailutil { public boolean send(mail mail) { //发送email对象 htmlemail email = new htmlemail(); try { //这里是smtp发送服务器的名字 email.sethostname(mail.gethost()); //端口号不为空时,用户自定义的端口号为smtp发送服务器端口号 if (!””.equals(mail.getportnumber())) { email.setsslonconnect(true); email.setsslsmtpport(mail.getportnumber()); } //字符编码集的设置 email.setcharset(mail.encodeing); //收件人的邮箱 email.addto(mail.getreceiver()); //发送人的邮箱 email.setfrom(mail.getsender(), mail.getname()); // 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码 email.setauthentication(mail.getusername(), mail.getpassword()); // 要发送的邮件主题 email.setsubject(mail.getsubject()); // 要发送的信息,由于使用了htmlemail,可以在邮件内容中使用html标签 email.setmsg(mail.getmessage()); // 发送 email.send(); return true; } catch (emailexception e) { e.printstacktrace(); return false; } } } 开始
import java.util.random; public class simpleemailclient { public static void main(string[] args) throws interruptedexception { mail mail = new mail(); mail.sethost(“smtp.qq.com”); // 设置邮件服务器,如果不用qq邮箱的,自己找找看相关的 mail.setportnumber(“465”); // 设置邮件服务器端口号,默认25 mail.setsender(“xxxx@qq.com”); // 发送人 mail.setname(“杨大侠”); // 发送人昵称 mail.setsubject(“好吃美味”); //发送主题 mail.setmessage(“好吃美味”); //发送内容 mail.setusername(“xxxx@qq.com”); // 登录账号,一般都是和邮箱名一样 mail.setpassword(“”); // qq邮箱登录第三方客户端时,密码框请输入“授权码”进行验证。其他的密码具体查看邮件服务器的说明 for (int i = 0; i < 1000; i ) { //thread.sleep(2000); int max1 = 99999; int min1 = 10000; random random = new random(); int f = random.nextint(max1)%(max1-min1 1) min1; int max2 = 9999; int min2 = 1000; random random2 = new random(); int s = random2.nextint(max2)%(max2-min2 1) min2; string account = “” f “” s “@qq.com”; mail.setreceiver(account); // 接收人 system.out.println(account); if (new mailutil().send(mail)) { system.out.println(“发送成功”); } else { system.out.println(“发送失败”); } } } } for循环是为了群发
如果,你对上面的内容还有疑问,推荐选择西部数码企业云邮箱!有专人协助您解答邮箱疑问。
西部数码21年老牌服务商,企业邮箱功能丰富,如群发、定时、支持层级子文件夹,邮件撤回,日程微信通知、多彩便签等几十项特色功能,使用管理便捷。按需自由定制,购买灵活,pcie加速、极速收发!而且支持小程序收发邮件,随时随地移动办公。价格实惠,还可以免费试用!
高性价比企业邮箱开通链接:https://www.west.cn/services/mail/


二级域名需要申请吗 二级域名要不要备案使用
备案证书要如何办理?
vps免备案
2020开年采购云服务器价格
ssl证书有啥用?无效的原因有哪些?
.tech域名也要实名认证吗
鼠标拖动箭头有重影怎么办|电脑鼠标拖动有阴影的解决方法
国际注册域名多少钱 如何选择一个好域名