本文整理匯總了Java中javax.mail.internet.MimeMessage.setSender方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.setSender方法的具體用法?Java MimeMessage.setSender怎麽用?Java MimeMessage.setSender使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.setSender方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage buildMail(MimeMessage message) {
MimeMessage ret = message;
try {
Address[] replies = {new InternetAddress(sSender)};
String[] recipients = sRecipients.split(",|;");
// Adding sender
ret.setFrom(new InternetAddress(sSender));
ret.setSender(new InternetAddress(sSender));
ret.setReplyTo(replies);
//Adding recipients
if (recipients[0].indexOf(":") != -1) {
ret.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[0].split(":")[1]));
} else {
ret.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients[0]));
}
for (int i = 1; i < recipients.length; i++) {
if (recipients[i].indexOf(":") != -1) {
String sRecipientType = recipients[i].split(":")[0];
String sRecipientAddress = recipients[i].split(":")[1];
if ("TO".equalsIgnoreCase(sRecipientType)) {
ret.addRecipient(Message.RecipientType.TO, new InternetAddress(sRecipientAddress));
} else if ("BCC".equalsIgnoreCase(sRecipientType)) {
ret.addRecipient(Message.RecipientType.BCC, new InternetAddress(sRecipientAddress));
} else {
ret.addRecipient(Message.RecipientType.CC, new InternetAddress(sRecipientAddress));
}
} else {
ret.addRecipient(Message.RecipientType.CC, new InternetAddress(recipients[i]));
}
}
//Add receipts
if (getDeliveryReceipt()) {
message.setHeader("Return-Receipt-To", new InternetAddress(sSender).toString());
}
if (getReadReceipt()) {
message.setHeader("Disposition-Notification-To", new InternetAddress(sSender).toString());
}
//Adding mail subject
ret.setSubject(sSubject);
//Adding content
if (bodyParts.size() > 0) {
Multipart multipart = new MimeMultipart();
MimeBodyPart msgPart = new MimeBodyPart();
msgPart.setContent(sMessageText, sContentType);
multipart.addBodyPart(msgPart);
for (BodyPart bodyPart : bodyParts) {
multipart.addBodyPart(bodyPart);
}
ret.setContent(multipart);
} else {
ret.setContent(sMessageText, sContentType);
}
} catch (Exception e1) {
Engine.logBeans.error("(SmtpStep) An error occured while trying to build e-mail : " + e1.getStackTrace().toString(), e1);
}
return ret;
}