本文整理匯總了Java中javax.mail.internet.MimeMessage.writeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.writeTo方法的具體用法?Java MimeMessage.writeTo怎麽用?Java MimeMessage.writeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeMessage
的用法示例。
在下文中一共展示了MimeMessage.writeTo方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: send
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Override
public void send(MimeMessage mimeMessage) throws MailException {
try {
System.out.println("---- START OF EMAIL MESSAGE ----");
System.out.println();
mimeMessage.writeTo(System.out);
System.out.println();
System.out.println("----- END OF EMAIL MESSAGE -----");
} catch (MessagingException | IOException e) {
LOG.error("Error sending to console: {}", e.getMessage());
}
}
示例2: createMessageWithEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private static Message createMessageWithEmail(MimeMessage emailContent) throws IOException, MessagingException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
emailContent.writeTo(buffer);
byte[] bytes = buffer.toByteArray();
String encodedEmail = Base64.encodeBase64URLSafeString(bytes);
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
示例3: createMessageWithEmail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
public static Message createMessageWithEmail(MimeMessage email)
throws MessagingException, IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
email.writeTo(bytes);
String encodedEmail = Base64.encodeToString(bytes.toByteArray(), Base64.URL_SAFE);
Message message = new Message();
message.setRaw(encodedEmail);
return message;
}
示例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: sendGMail
import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
* Fetch a list of Gmail labels attached to the specified account.
*
* @return List of Strings labels.
*/
private List<String> sendGMail() throws Exception {
List<String> retVal = new ArrayList<>();
if (debugLogFileWriter != null) {
debugLogFileWriter.appendnl("sendGMail begin");
debugLogFileWriter.flush();
}
//create the message
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("me"));
mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(mEmailTo));
mimeMessage.setSubject(mSubject);
MimeBodyPart mimeBodyText = new MimeBodyPart();
mimeBodyText.setContent(mMessage, "text/html");
mimeBodyText.setHeader("Content-Type", "text/html; charset=\"UTF-8\"");
Multipart mp = new MimeMultipart();
mp.addBodyPart(mimeBodyText);
if (mAttachments != null && mAttachments.size() > 0) {
for (String attachment : mAttachments) {
File attach = new File(attachment);
if (!attach.exists()) {
throw new IOException("File not found");
}
MimeBodyPart mimeBodyAttachments = new MimeBodyPart();
String fileName = attach.getName();
FileInputStream is = new FileInputStream(attach);
DataSource source = new ByteArrayDataSource(is, "application/zip");
mimeBodyAttachments.setDataHandler(new DataHandler(source));
mimeBodyAttachments.setFileName(fileName);
mimeBodyAttachments.setHeader("Content-Type", "application/zip" + "; name=\"" + fileName + "\"");
mimeBodyAttachments.setDisposition(MimeBodyPart.ATTACHMENT);
mp.addBodyPart(mimeBodyAttachments);
}
// mimeBodyAttachments.setHeader("Content-Transfer-Encoding", "base64");
}
mimeMessage.setContent(mp);
// mimeMessage.setText(mMessage);
//encode in base64url string
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
mimeMessage.writeTo(bytes);
String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());
//create the message
Message message = new Message();
message.setRaw(encodedEmail);
if (debugLogFileWriter != null) {
debugLogFileWriter.appendnl("sending message using com.google.api.services.gmail.Gmail begin");
debugLogFileWriter.flush();
}
//send the message ("me" => the current selected google account)
Message result = mGmailService.users().messages().send("me", message).execute();
if (debugLogFileWriter != null) {
debugLogFileWriter.appendnl("sending message using com.google.api.services.gmail.Gmail ended with result:\n")
.append(result.toPrettyString());
debugLogFileWriter.flush();
}
retVal.add(AndiCar.getAppResources().getString(R.string.gen_mail_sent));
return retVal;
}