本文整理汇总了Java中javax.mail.internet.MimeMessage.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessage.setHeader方法的具体用法?Java MimeMessage.setHeader怎么用?Java MimeMessage.setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.setHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public void sendEmail(String address, String subject, String content, Map<String, String> headers) throws Exception {
Session session = MailUtilities.makeSession();
if (session == null) {
// LogService.getRoot().warning("Unable to create mail session. Not sending mail to "+address+".");
LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.MailSenderSMTP.creating_mail_session_error",
address);
}
MimeMessage msg = new MimeMessage(session);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setFrom();
msg.setSubject(subject, "UTF-8");
msg.setSentDate(new Date());
msg.setText(content, "UTF-8");
if (headers != null) {
for (Entry<String, String> header : headers.entrySet()) {
msg.setHeader(header.getKey(), header.getValue());
}
}
Transport.send(msg);
}
示例2: send
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public void send(String senderAddress, String senderName, String recipient, String content) {
if (StringUtils.isBlank(senderAddress)) {
throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
"You must set a value for notifications to work");
}
if (StringUtils.isBlank(content)) {
throw new InternalServerError("Notification content is empty");
}
try {
InternetAddress sender = new InternetAddress(senderAddress, senderName);
MimeMessage msg = new MimeMessage(session, IOUtils.toInputStream(content, StandardCharsets.UTF_8));
msg.setHeader("X-Mailer", "mxisd"); // FIXME set version
msg.setSentDate(new Date());
msg.setFrom(sender);
msg.setRecipients(Message.RecipientType.TO, recipient);
msg.saveChanges();
log.info("Sending invite to {} via SMTP using {}:{}", recipient, cfg.getHost(), cfg.getPort());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.setStartTLS(cfg.getTls() > 0);
transport.setRequireStartTLS(cfg.getTls() > 1);
log.info("Connecting to {}:{}", cfg.getHost(), cfg.getPort());
transport.connect(cfg.getHost(), cfg.getPort(), cfg.getLogin(), cfg.getPassword());
try {
transport.sendMessage(msg, InternetAddress.parse(recipient));
log.info("Invite to {} was sent", recipient);
} finally {
transport.close();
}
} catch (UnsupportedEncodingException | MessagingException e) {
throw new RuntimeException("Unable to send e-mail invite to " + recipient, e);
}
}
示例3: send
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private void send(MimeMessage msg) throws MessagingException {
msg.setHeader("X-Mailer", "matrix-appservice-email");
msg.setSentDate(new Date());
msg.setRecipients(Message.RecipientType.TO, getIdentity());
SMTPTransport transport = (SMTPTransport) session.getTransport("smtp");
transport.setStartTLS(cfg.getTls() > 0);
transport.setRequireStartTLS(cfg.getTls() > 1);
transport.connect(cfg.getHost(), cfg.getPort(), cfg.getLogin(), cfg.getPassword());
log.info("Sending email via SMTP using {}:{}", cfg.getHost(), cfg.getPort());
try {
transport.sendMessage(msg, InternetAddress.parse(getIdentity()));
} catch (MessagingException e) {
log.error("mmm", e);
} finally {
transport.close();
}
}
示例4: 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;
}