Topic: Javamail给多人发信的问题,您进来看看我十分感谢!

  Print this page

1.Javamail给多人发信的问题,您进来看看我十分感谢! Copy to clipboard
Posted by: xinzi
Posted on: 2005-01-27 15:02

我用的是transport.sendMessage(message, message.getAllRecipients());的方法,message中有多个用户,如果有用户的地址不正确,信就一封也不发送成功。如果Email地址全部正确,则发送成功。
不成功时的Log信息如下:


DEBUG SMTP: use8bit false
DEBUG SMTP SENT: RCPT TO:<goodpi@126.com>
DEBUG SMTP RCVD: 250 Ok

DEBUG SMTP SENT: RCPT TO:<chenggong@126.com>
DEBUG SMTP RCVD: 250 Ok

DEBUG SMTP SENT: RCPT TO:<hunhun@126.com>
DEBUG SMTP RCVD: 250 Ok

DEBUG SMTP SENT: RCPT TO:<ghfghfghfg@126.com>
DEBUG SMTP RCVD: 550 <ghfghfghfg@126.com>: Invalid User

Valid Unsent Addresses
goodpi@126.com
chenggong@126.com
hunhun@126.com
Invalid Addresses
ghfghfghfg@126.com
DEBUG SMTPTransport: Sending failed because of invalid destination addresses
DEBUG SMTP SENT: RSET
DEBUG SMTP RCVD: 250 Ok

15:05:54,593 INFO EmailSendTask: Email Send Exception: MessagingException
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
  javax.mail.SendFailedException: 550 <ghfghfghfg@126.com>: Invalid User

  at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:804)
  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:320)
  at com.newchannel.isms.service.mail.EmailSendTask$SmtpProxy.send(EmailSendTask.java:449)
  at com.newchannel.isms.service.mail.EmailSendTask.run(EmailSendTask.java:115)
  at com.newchannel.isms.service.mail.EmailSendTask.main(EmailSendTask.java:591)
DEBUG SMTP SENT: QUIT


我已经设置mailProps.put("mail.stmp.sendpartial", "true");
按照文档应该会给正确地址发信,为什么不这么作。
请有经验的网友帮忙看看,作不好我就惨了。谢谢!

2.Re:Javamail给多人发信的问题,您进来看看我十分感谢! [Re: xinzi] Copy to clipboard
Posted by: xinzi
Posted on: 2005-01-28 13:38

没人给点意见吗?

3.Re:Javamail给多人发信的问题,您进来看看我十分感谢! [Re: xinzi] Copy to clipboard
Posted by: bluepure
Posted on: 2005-01-28 19:28

直接transport.sendMessage(message);

地址以及写在message里了,就不用单独传参数过去了吧?

4.Re:Javamail给多人发信的问题,您进来看看我十分感谢! [Re: xinzi] Copy to clipboard
Posted by: xinzi
Posted on: 2005-01-29 00:11

先谢谢楼上的回复。
但这个方法我试过,sendMessage(message);是静态方法,我调用这个方法,new的Transport对象就连不到SMTP服务器(打开JavaMail debug信息看到)

5.Re:Javamail给多人发信的问题,您进来看看我十分感谢! [Re: xinzi] Copy to clipboard
Posted by: bluepure
Posted on: 2005-01-29 01:03

给你看个我前几天写的例子:

<%@page contentType="text/html; charset=GBK"%>
<%@page import="javax.mail.internet.*"%>
<%@page import="javax.mail.*"%>
<html>
<head>
<title>发送结果!!!</title>
</head>
<body bgcolor="#ffffff">
<%
try {
String toAddr = request.getParameter("toAddr");
if (toAddr == null) {
%>
收件人不能够为空
<%
return;
}
String sender = request.getParameter("sender");
if (sender == null) {
%>
发件人不能够为空
<%
return;
}
String password = request.getParameter("password");
if (password == null) {
%>
请输入密码
<%
return;
}
String subject = request.getParameter("subject");
if (subject == null) {
subject = "无主题";
}
String content = request.getParameter("content");
if (content == null) {
content = "无内容";
}
content=content+"\n\n\n\n发件人IP地址: "+request.getRemoteAddr();
java.util.Properties hostpros = new java.util.Properties();
hostpros.setProperty("mail.smtp.host", "127.0.0.1");
hostpros.setProperty("mail.smtp.port", "25");
hostpros.setProperty("mail.smtp.auth", "true");
hostpros.setProperty("mailservername", "mydomain.com");
javax.mail.Session mailsession = Session.getInstance(hostpros, (Authenticator)new com.webmail.entitys.MailAuthenticator(sender,
password));
Message msg = new MimeMessage(mailsession);
msg.setFrom(new InternetAddress(sender+"@dayawan.gd"));
msg.setRecipient(Message.RecipientType.TO,new InternetAddress(toAddr));
msg.setSubject(subject);
msg.setText(content);
mailsession.getTransport("smtp").send(msg);
mailsession.getTransport("smtp").close();
out.print("邮件发送成功!!!");
} catch (Exception ex) {
%>
发送邮件失败了::
<%=ex.getMessage() %><%
return;
} finally {
%>
</body>
</html>
<%}%>

6.Re:Javamail给多人发信的问题,您进来看看我十分感谢! [Re: xinzi] Copy to clipboard
Posted by: xinzi
Posted on: 2005-01-30 00:01

楼上朋友 你的这个程序可以发送给多人吗?

7.Re:Javamail给多人发信的问题,您进来看看我十分感谢! [Re: xinzi] Copy to clipboard
Posted by: bluepure
Posted on: 2005-01-30 23:29

发送给多人是要使用下面这个方法:
使用地址数组:
msg.setRecipients(Message.RecipientType.TO,InternetAddress[]{new InternetAddress(toAddr)});

仔细看javadoc就知道了。
/**
* Set the recipient addresses. All addresses of the specified
* type are replaced by the addresses parameter.
*
* @param type the recipient type
* @param addresses the addresses
* @exception MessagingException
* @exception  IllegalWriteException if the underlying
*      implementation does not support modification
*      of existing values
* @exception  IllegalStateException if this message is
*      obtained from a READ_ONLY folder.
*/
public abstract void setRecipients(RecipientType type, Address[] addresses)
throws MessagingException;


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923