public boolean senderEmail(List list,MailMessage message) {// javax.mail.Address a=new InternetAddress();// 截取出发件箱的服务器String form = message.getFromEmail();// 得到@的索引int index = form.indexOf('@');// 得到字符串长度in

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 09:23:49
public boolean senderEmail(List list,MailMessage message) {// javax.mail.Address a=new InternetAddress();// 截取出发件箱的服务器String form = message.getFromEmail();// 得到@的索引int index = form.indexOf('@');// 得到字符串长度in
xVnF^B,e-Pؒ q5lTz/(j%1ұQ66nA Z0 YJ!u.#B>E\Μ=sf7eǶPul0`0mGf9/"f̬aԈYu.n+! -dn)\YxwV;ytz'v!6)rj 1F ϩۈ2(pN_؄#^(lȗvڕT@vE~c|e LGlxHd^> !'w0z ]GNai2v-h Z*NC`$xB,SÔۘ!(l`|ed!X{Fe͌Oc%6 ǡ4ڒ0;ݳؔ07M5\dw{p$ ԥiK2iFY1z1#eCCG3b15*Y qgIRQgǗز=bcb)y(- =ʼn$4E Q7IMv;E{C2DM~Qýe;.$BLǩu҅'%X:f`ƞBVoҿ2UGª=.X*1sphi'D _OEO T] ô9lM a? ЃV;ꬭ׿?>Oн?xLp}ˑ(KHLYY;f0, g~=0<ՙ|Λ ܗ& hl<  _>< xCF

public boolean senderEmail(List list,MailMessage message) {// javax.mail.Address a=new InternetAddress();// 截取出发件箱的服务器String form = message.getFromEmail();// 得到@的索引int index = form.indexOf('@');// 得到字符串长度in
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

public boolean senderEmail(List list,MailMessage message) {// javax.mail.Address a=new InternetAddress();// 截取出发件箱的服务器String form = message.getFromEmail();// 得到@的索引int index = form.indexOf('@');// 得到字符串长度in
response:421查一下这个就知道哪里出错了