當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaMailSender.createMimeMessage方法代碼示例

本文整理匯總了Java中org.springframework.mail.javamail.JavaMailSender.createMimeMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaMailSender.createMimeMessage方法的具體用法?Java JavaMailSender.createMimeMessage怎麽用?Java JavaMailSender.createMimeMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.mail.javamail.JavaMailSender的用法示例。


在下文中一共展示了JavaMailSender.createMimeMessage方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendPasswordResetMail

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
@Async
public void sendPasswordResetMail(String target,String reseturl,JavaMailSender javaMailSender) throws InterruptedException  {
	try {
		MimeMessage mimeMsg = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
		String content = (String) PropertyPlaceholder.getProperty("mail.template");
		content = content.replace("{reseturl}", reseturl);
		helper.setText(content, true);
		helper.setTo(new String[]{target});
		String title = (String) PropertyPlaceholder.getProperty("mail.title");
		helper.setSubject(title); 
		String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
		String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
		helper.setFrom(authormail,authorname);
		javaMailSender.send(mimeMsg);
		log.info("Password Reset Mail has been send to "+target);
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zjlywjh001,項目名稱:PhrackCTF-Platform-Personal,代碼行數:21,代碼來源:MailUtil.java

示例2: createHtmlEmail

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
private static void createHtmlEmail(int i){
    try {
        JavaMailSender sender = getEmailSender();

        MimeMessage message = sender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message);
        helper.setTo("[email protected]");
        helper.setFrom("[email protected]");
        helper.setSubject("Test-Mail " + i);
        helper.setText("<html><head></head><body>This is the test mail number " + i + "</body>", true);

        sender.send(message);
    } catch (MessagingException e){
        throw new RuntimeException("Failed to create mail", e);
    }
}
 
開發者ID:gessnerfl,項目名稱:fake-smtp-server,代碼行數:17,代碼來源:TestDataCreator.java

示例3: mailTo

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
@Async
public void mailTo(String[] targetuser,String title,String content,JavaMailSender javaMailSender) {//郵件功能
	try {
		MimeMessage mimeMsg = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
		helper.setText(content, true);
		helper.setBcc(targetuser);
		helper.setSubject(title);
		String authormail = (String) PropertyPlaceholder.getProperty("mail.sendfrom");
		String authorname = (String) PropertyPlaceholder.getProperty("mail.sendname");
		helper.setFrom(authormail,authorname);
		javaMailSender.send(mimeMsg);
		log.info("Mail send to "+Arrays.toString(targetuser));
	} catch(Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:zjlywjh001,項目名稱:PhrackCTF-Platform-Team,代碼行數:18,代碼來源:MailUtil.java

示例4: testCreateMimeMessageWithExceptionInInputStream

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
@Test
public void testCreateMimeMessageWithExceptionInInputStream() throws Exception {
    InputStream inputStream = mock(InputStream.class);

    AmazonSimpleEmailService emailService = mock(AmazonSimpleEmailService.class);

    JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(emailService);

    IOException ioException = new IOException("error");
    when(inputStream.read(ArgumentMatchers.any(byte[].class), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenThrow(ioException);

    try {
        mailSender.createMimeMessage(inputStream);
        fail("MailPreparationException expected due to error while creating mail");
    } catch (MailParseException e) {
        assertTrue(e.getMessage().startsWith("Could not parse raw MIME content"));
        assertSame(ioException, e.getCause().getCause());
    }
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:20,代碼來源:SimpleEmailServiceJavaMailSenderTest.java

示例5: sendMailSpring

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
/**
 * 發送郵件 (完整版)(結合Spring)
 * 
 * //@param javaMailSender: 發送Bean
 * //@param sendFrom		: 發送人郵箱
 * //@param sendNick		: 發送人昵稱
 * @param toAddress		: 收件人郵箱
 * @param mailSubject	: 郵件主題
 * @param mailBody		: 郵件正文
 * @param mailBodyIsHtml: 郵件正文格式,true:HTML格式;false:文本格式
 * @param attachments	: 附件
 */
@SuppressWarnings("null")
public static boolean sendMailSpring(String toAddress, String mailSubject, String mailBody, boolean mailBodyIsHtml,File[] attachments) {
	JavaMailSender javaMailSender = null;//ResourceBundle.getInstance().getJavaMailSender();
	try {
		MimeMessage mimeMessage = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8"); // 設置utf-8或GBK編碼,否則郵件會有亂碼;multipart,true表示文件上傳


		helper.setFrom(username, sendNick);
		helper.setTo(toAddress);

		// 設置收件人抄送的名片和地址(相當於群發了)
		//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("郵箱001") + " <@163.com>," + MimeUtility.encodeText("郵箱002") + " <@foxmail.com>"));

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml);
		
		// 添加附件
		if (ArrayUtils.isNotEmpty(attachments)) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}
		
		// 群發
		//MimeMessage[] mailMessages = { mimeMessage };
		
		javaMailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
	return false;
}
 
開發者ID:mmwhd,項目名稱:stage-job,代碼行數:47,代碼來源:MailUtil.java

示例6: sendMailSpring

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
/**
 * 發送郵件 (完整版)(結合Spring)
 * 
 * //@param javaMailSender: 發送Bean
 * //@param sendFrom		: 發送人郵箱
 * //@param sendNick		: 發送人昵稱
 * @param toAddress		: 收件人郵箱
 * @param mailSubject	: 郵件主題
 * @param mailBody		: 郵件正文
 * @param mailBodyIsHtml: 郵件正文格式,true:HTML格式;false:文本格式
 * @param attachments	: 附件
 */
@SuppressWarnings("null")
public static boolean sendMailSpring(String toAddress, String mailSubject, String mailBody, boolean mailBodyIsHtml,File[] attachments) {
	JavaMailSender javaMailSender = null;//ResourceBundle.getInstance().getJavaMailSender();
	try {
		MimeMessage mimeMessage = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, ArrayUtils.isNotEmpty(attachments), "UTF-8"); // 設置utf-8或GBK編碼,否則郵件會有亂碼;multipart,true表示文件上傳
		
		helper.setFrom(sendFrom, sendNick);
		helper.setTo(toAddress);

		// 設置收件人抄送的名片和地址(相當於群發了)
		//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("郵箱001") + " <@163.com>," + MimeUtility.encodeText("郵箱002") + " <@foxmail.com>"));

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml);
		
		// 添加附件
		if (ArrayUtils.isNotEmpty(attachments)) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}
		
		// 群發
		//MimeMessage[] mailMessages = { mimeMessage };
		
		javaMailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		logger.info("{}", e);
	}
	return false;
}
 
開發者ID:kevinKaiF,項目名稱:xxl-job,代碼行數:46,代碼來源:MailUtil.java

示例7: sendMailSpring

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
/**
 * 發送郵件 (完整版)(結合Spring)
 * 
 * @param toAddress		: 收件人郵箱
 * @param mailSubject	: 郵件主題
 * @param mailBody		: 郵件正文
 * @param mailBodyIsHtml: 郵件正文格式,true:HTML格式;false:文本格式
 * @param attachments	: 附件
 */
public static boolean sendMailSpring(String toAddress, String mailSubject, String mailBody,
		boolean mailBodyIsHtml,File[] attachments) {
	JavaMailSender javaMailSender = (JavaMailSender) SpringContentAwareUtil.getBeanByName("javaMailSender");
	try {
		MimeMessage mimeMessage = javaMailSender.createMimeMessage();
		MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, (attachments!=null && attachments.length>0), "UTF-8"); // 設置utf-8或GBK編碼,否則郵件會有亂碼;multipart,true表示文件上傳
		
		helper.setFrom(username, sendNick);
		helper.setTo(toAddress);

		// 設置收件人抄送的名片和地址(相當於群發了)
		//helper.setCc(InternetAddress.parse(MimeUtility.encodeText("郵箱001") + " <@163.com>," + MimeUtility.encodeText("郵箱002") + " <@foxmail.com>"));

		helper.setSubject(mailSubject);
		helper.setText(mailBody, mailBodyIsHtml);
		
		// 添加附件
		if (attachments!=null && attachments.length>0) {
			for (File file : attachments) {
				helper.addAttachment(MimeUtility.encodeText(file.getName()), file);	
			}
		}
		
		// 群發
		//MimeMessage[] mailMessages = { mimeMessage };
		
		javaMailSender.send(mimeMessage);
		return true;
	} catch (Exception e) {
		logger.info("{}", e);
	}
	return false;
}
 
開發者ID:xuxueli,項目名稱:xxl-incubator,代碼行數:43,代碼來源:MailUtil.java

示例8: send

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
public static void send(EmailHelper emailHelper, JavaMailSender javaMailSender) throws MessagingException {
    MimeMessage message = javaMailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");

    helper.setTo(emailHelper.to);
    helper.setFrom(emailHelper.from); //to avoid spam filters
    helper.setReplyTo(emailHelper.replyTo);
    helper.setSubject(emailHelper.subject);
    helper.setText(emailHelper.text, emailHelper.html);

    javaMailSender.send(message);

}
 
開發者ID:solita,項目名稱:kansalaisaloite,代碼行數:15,代碼來源:EmailSender.java

示例9: createMimeMessage_withDefaultPropertiesAndNoEncodingAndFileTypeMap_returnsSessionWithEmptyProperties

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
@Test
public void createMimeMessage_withDefaultPropertiesAndNoEncodingAndFileTypeMap_returnsSessionWithEmptyProperties() throws Exception {
    // Arrange
    JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(null);

    // Act
    MimeMessage mimeMessage = mailSender.createMimeMessage();

    // Assert
    assertNotNull(mimeMessage);
    assertEquals(0, mimeMessage.getSession().getProperties().size());
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:13,代碼來源:SimpleEmailServiceJavaMailSenderTest.java

示例10: testCreateMimeMessageFromPreDefinedMessage

import org.springframework.mail.javamail.JavaMailSender; //導入方法依賴的package包/類
@Test
public void testCreateMimeMessageFromPreDefinedMessage() throws Exception {
    JavaMailSender mailSender = new SimpleEmailServiceJavaMailSender(null);

    MimeMessage original = createMimeMessage();

    MimeMessage mimeMessage = mailSender.createMimeMessage(new ByteArrayInputStream(getMimeMessageAsByteArray(original)));
    assertNotNull(mimeMessage);
    assertEquals(original.getSubject(), mimeMessage.getSubject());
    assertEquals(original.getContent(), mimeMessage.getContent());
    assertEquals(original.getRecipients(Message.RecipientType.TO)[0], mimeMessage.getRecipients(Message.RecipientType.TO)[0]);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:13,代碼來源:SimpleEmailServiceJavaMailSenderTest.java


注:本文中的org.springframework.mail.javamail.JavaMailSender.createMimeMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。