java里如何判断Email是否发送成功?

03-09-10 vvivv
java里如何判断Email是否发送成功?

renzy
2003-09-13 15:21
public boolean send_notify_email(String content, String from, String to, String cc, String bcc, String smtphost, String subject)

throws Exception {

try {

Properties props = System.getProperties();

// Setup mail server

props.put("mail.smtp.host", smtphost);

// Get session

Session session = Session.getInstance(props, null);

// Define message

MimeMessage message = new MimeMessage(session);

message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));

message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc, false));

message.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(bcc, false));

message.setSubject(subject);

message.setFrom(new InternetAddress(from));

String mailer="servlet";

message.setHeader("X-Mailer", mailer);

message.setSentDate(new Date());

//message.setText(content,"gb2312");

message.setDataHandler(new DataHandler(new servinfo.ByteArrayDataSource(content, "text/html")));

// Send message

Transport.send(message);

return true;

} catch (Exception e) {

ostr = new ByteArrayOutputStream();

e.printStackTrace(new PrintStream(ostr));

return false;

}

}

返回true发送成功,返回false发送失败

猜你喜欢