当前位置: 首页>>代码示例>>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;未经允许,请勿转载。