当前位置: 首页>>代码示例>>Java>>正文


Java MimeMessage.writeTo方法代码示例

本文整理汇总了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());
	}
}
 
开发者ID:mychalvlcek,项目名称:spring-rest-skeleton,代码行数:15,代码来源:ConsoleMailSender.java

示例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;
}
 
开发者ID:tburne,项目名称:blog-examples,代码行数:10,代码来源:ClientRequestAPI.java

示例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;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:10,代码来源:EmailShield.java

示例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;
}
 
开发者ID:markwest1972,项目名称:smart-security-camera,代码行数:72,代码来源:SesSendNotificationHandler.java

示例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;
    }
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:80,代码来源:SendGMailTask.java


注:本文中的javax.mail.internet.MimeMessage.writeTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。