JavaMail深入浅出(2)计算机等级考试
文章作者 100test 发表时间 2010:01:30 10:39:31
来源 100Test.Com百考试题网
/**
* SendMailService 构造子注解。
*/
public SendMail() {
super().
}
private void fillMail(Session session,MimeMessage msg) throws IOException, MessagingException{
String fileName = null.
Multipart mPart = new MimeMultipart().
if (mailFrom != null) {
msg.setFrom(new InternetAddress(mailFrom)).
System.out.println("发送人Mail地址:" mailFrom).
} else {
System.out.println("没有指定发送人邮件地址!").
return.
}
if (mailTo != null) {
InternetAddress[] address = InternetAddress.parse(mailTo).
msg.setRecipients(Message.RecipientType.TO, address).
System.out.println("收件人Mail地址:" mailTo).
} else {
System.out.println("没有指定收件人邮件地址!").
return.
}
if (mailccTo != null) {
InternetAddress[] ccaddress = InternetAddress.parse(mailccTo).
System.out.println("CCMail地址:" mailccTo).
msg.setRecipients(Message.RecipientType.CC, ccaddress).
}
if (mailbccTo != null) {
InternetAddress[] bccaddress = InternetAddress.parse(mailbccTo).
System.out.println("BCCMail地址:" mailbccTo).
msg.setRecipients(Message.RecipientType.BCC, bccaddress).
}
msg.setSubject(subject).
InternetAddress[] replyAddress = { new InternetAddress(mailFrom)}.
msg.setReplyTo(replyAddress).
// create and fill the first message part
MimeBodyPart mBodyContent = new MimeBodyPart().
if (msgContent != null)
mBodyContent.setContent(msgContent, messageContentMimeType).
else
mBodyContent.setContent("", messageContentMimeType).
mPart.addBodyPart(mBodyContent).