本文整理汇总了Java中javax.mail.internet.MimeMessage.setReplyTo方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessage.setReplyTo方法的具体用法?Java MimeMessage.setReplyTo怎么用?Java MimeMessage.setReplyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.setReplyTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private static void sendEmail(String fromEmail, String toEmail, String subject, String body, boolean html)
throws MessagingException{
MimeMessage message = new MimeMessage(MAILING_SESSION);
message.setFrom(new InternetAddress(fromEmail));
InternetAddress[] addresses = InternetAddress.parse(toEmail);//one or more addresses
message.addRecipients(RecipientType.TO, addresses);
message.setReplyTo(addresses);
message.setSubject(subject);
String subType;
if(html){
subType = "html";
}else{
subType = "plain";
}
message.setText(body, "UTF-8", subType);
Transport.send(message);
}
示例2: makeEmail
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
private MimeMessage makeEmail(TokenData data, _EmailTemplate template, MimeMultipart body, boolean allowReply) throws MessagingException, UnsupportedEncodingException {
MimeMessage msg = new MimeMessage(session);
if (allowReply) {
msg.setReplyTo(InternetAddress.parse(recvCfg.getEmail().replace("%KEY%", data.getKey())));
}
String sender = data.isSelf() ? sendCfg.getName() : data.getSenderName();
msg.setFrom(new InternetAddress(sendCfg.getEmail(), sender, StandardCharsets.UTF_8.name()));
msg.setSubject(processToken(data, template.getSubject()));
msg.setContent(body);
return msg;
}
示例3: 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;
}
示例4: handleRequest
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
@Override
public Parameters handleRequest(Parameters parameters, Context context) {
context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
try {
// Create an empty Mime message and start populating it
Session session = Session.getDefaultInstance(new Properties());
MimeMessage message = new MimeMessage(session);
message.setSubject(EMAIL_SUBJECT, "UTF-8");
message.setFrom(new InternetAddress(System.getenv("EMAIL_FROM")));
message.setReplyTo(new Address[] { new InternetAddress(System.getenv("EMAIL_FROM")) });
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(System.getenv("EMAIL_RECIPIENT")));
MimeBodyPart wrap = new MimeBodyPart();
MimeMultipart cover = new MimeMultipart("alternative");
MimeBodyPart html = new MimeBodyPart();
cover.addBodyPart(html);
wrap.setContent(cover);
MimeMultipart content = new MimeMultipart("related");
message.setContent(content);
content.addBodyPart(wrap);
// Create an S3 URL reference to the snapshot that will be attached to this email
URL attachmentURL = createSignedURL(parameters.getS3Bucket(), parameters.getS3Key());
StringBuilder sb = new StringBuilder();
String id = UUID.randomUUID().toString();
sb.append("<img src=\"cid:");
sb.append(id);
sb.append("\" alt=\"ATTACHMENT\"/>\n");
// Add the attachment as a part of the message body
MimeBodyPart attachment = new MimeBodyPart();
DataSource fds = new URLDataSource(attachmentURL);
attachment.setDataHandler(new DataHandler(fds));
attachment.setContentID("<" + id + ">");
attachment.setDisposition(BodyPart.ATTACHMENT);
attachment.setFileName(fds.getName());
content.addBodyPart(attachment);
// Pretty print the Rekognition Labels as part of the Emails HTML content
String prettyPrintLabels = parameters.getRekognitionLabels().toString();
prettyPrintLabels = prettyPrintLabels.replace("{", "").replace("}", "");
prettyPrintLabels = prettyPrintLabels.replace(",", "<br>");
html.setContent("<html><body><h2>Uploaded Filename : " + parameters.getS3Key().replace("upload/", "") +
"</h2><p><b>Detected Labels/Confidence</b><br><br>" + prettyPrintLabels + "</p>"+sb+"</body></html>", "text/html");
// Convert the JavaMail message into a raw email request for sending via SES
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.writeTo(outputStream);
RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
// Send the email using the AWS SES Service
AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.defaultClient();
client.sendRawEmail(rawEmailRequest);
} catch (MessagingException | IOException e) {
// Convert Checked Exceptions to RuntimeExceptions to ensure that
// they get picked up by the Step Function infrastructure
throw new AmazonServiceException("Error in ["+context.getFunctionName()+"]", e);
}
context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
return parameters;
}
示例5: prepareMimeMessage
import javax.mail.internet.MimeMessage; //导入方法依赖的package包/类
protected MimeMessage prepareMimeMessage(MailInfo mailInfo)
throws MessagingException {
Session session = getMailSession(mailInfo);
MimeMessage mimeMessage = new MimeMessage(session);
Address[] toAddresses = InternetAddress.parse(mailInfo.getTo());
mimeMessage.setRecipients(Message.RecipientType.TO, toAddresses);
if (mailInfo.getCc() != null) {
Address[] ccAddresses = InternetAddress.parse(mailInfo.getCc());
mimeMessage.setRecipients(Message.RecipientType.CC, ccAddresses);
}
mimeMessage.setFrom(new InternetAddress(mailInfo.getFrom()));
if (mailInfo.getReplyTo() != null) {
mimeMessage.setReplyTo(new InternetAddress[]{new InternetAddress(mailInfo.getReplyTo())});
}
mimeMessage.setSubject(mailInfo.getSubject());
mimeMessage.setSentDate(new Date());
setMimeMessageContent(mimeMessage, mailInfo);
return mimeMessage;
}