public boolean senderEmail(List list,MailMessage message) {
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/07 16:53:39
public boolean senderEmail(List list,MailMessage message) {
// javax.mail.Address a=new InternetAddress();
// 截取出发件箱的服务器
String form = message.getFromEmail();
// 得到@的索引
int index = form.indexOf('@');
// 得到字符串长度
int length = form.length();
// 截取字符串
String server = form.substring(index + 1,length);
// 建立邮件会话
Properties pro = new Properties();
pro.put("mail.smtp.host","smtp." + server);
pro.put("mail.smtp.auth","true");
Session sess = Session.getInstance(pro);
sess.setDebug(true);
try {
// 新建一个消息对象
MimeMessage mimeMessage = new MimeMessage(sess);
// 设置发件人
InternetAddress from_mail = new InternetAddress(message
.getFromEmail());
mimeMessage.setFrom(from_mail);
// 设置主题
// mimeMessage.setSubject(message.getSubject(),"text/html;charset=utf-8");
mimeMessage.setSubject(message.getSubject());
// 设置内容
mimeMessage.setText(message.getMessageText());
// 设置发送时间
mimeMessage.setSentDate(new Date());
// 循环发邮件
for (Object object :list) {
for (int i = 0; i < 100; i++) {
String toEmail = (String) object;
// 设置收件人
InternetAddress to_mail = new InternetAddress(toEmail);
mimeMessage.setRecipient(Message.RecipientType.TO,to_mail);
// 发送邮件
mimeMessage.saveChanges(); // 保存邮件信息
Transport transport = sess.getTransport("smtp");
// 登陆
transport.connect("smtp." + server,message.getFromEmail(),
message.getPassword());
transport.sendMessage(mimeMessage,mimeMessage
.getAllRecipients());
Thread.sleep(1000);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("发送失败.");
return false;
}
return true;
}
写了个for循环发送邮件,为什么发送几天后就会报错?
Could not connect to SMTP host:smtp.sina.com.cn,port:25,response:421
// javax.mail.Address a=new InternetAddress();
// 截取出发件箱的服务器
String form = message.getFromEmail();
// 得到@的索引
int index = form.indexOf('@');
// 得到字符串长度
int length = form.length();
// 截取字符串
String server = form.substring(index + 1,length);
// 建立邮件会话
Properties pro = new Properties();
pro.put("mail.smtp.host","smtp." + server);
pro.put("mail.smtp.auth","true");
Session sess = Session.getInstance(pro);
sess.setDebug(true);
try {
// 新建一个消息对象
MimeMessage mimeMessage = new MimeMessage(sess);
// 设置发件人
InternetAddress from_mail = new InternetAddress(message
.getFromEmail());
mimeMessage.setFrom(from_mail);
// 设置主题
// mimeMessage.setSubject(message.getSubject(),"text/html;charset=utf-8");
mimeMessage.setSubject(message.getSubject());
// 设置内容
mimeMessage.setText(message.getMessageText());
// 设置发送时间
mimeMessage.setSentDate(new Date());
// 循环发邮件
for (Object object :list) {
for (int i = 0; i < 100; i++) {
String toEmail = (String) object;
// 设置收件人
InternetAddress to_mail = new InternetAddress(toEmail);
mimeMessage.setRecipient(Message.RecipientType.TO,to_mail);
// 发送邮件
mimeMessage.saveChanges(); // 保存邮件信息
Transport transport = sess.getTransport("smtp");
// 登陆
transport.connect("smtp." + server,message.getFromEmail(),
message.getPassword());
transport.sendMessage(mimeMessage,mimeMessage
.getAllRecipients());
Thread.sleep(1000);
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("发送失败.");
return false;
}
return true;
}
写了个for循环发送邮件,为什么发送几天后就会报错?
Could not connect to SMTP host:smtp.sina.com.cn,port:25,response:421
esponse:421查一下这个就知道哪里出错了
public boolean senderEmail(List list,MailMessage message) {
public List Children { get; private set;
public List append(new Cons (that,this)) that 和 this 都是list,
make a list of public opinion 为什么错的
List list=criteria.list()怎么解释
list是什么意思
A-List
contact list
list of
英语翻译(六)Muster listThe muster list is posted in public places
TASK LIST TO DO LIST怎么样
students to list the names?[list]