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


Java MimeMessageHelper.addInline方法代码示例

本文整理汇总了Java中org.springframework.mail.javamail.MimeMessageHelper.addInline方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessageHelper.addInline方法的具体用法?Java MimeMessageHelper.addInline怎么用?Java MimeMessageHelper.addInline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.mail.javamail.MimeMessageHelper的用法示例。


在下文中一共展示了MimeMessageHelper.addInline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendRichSpitterEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void sendRichSpitterEmail(String to, Spittle spittle) throws MessagingException {  
  MimeMessage message = mailSender.createMimeMessage();
  MimeMessageHelper helper = new MimeMessageHelper(message, true);
  helper.setFrom("[email protected]");
  helper.setTo("[email protected]");
  helper.setSubject("New spittle from " + 
          spittle.getSpitter().getFullName());
  
  helper.setText("<html><body><img src='cid:spitterLogo'>" + //<co id="co_setHtml"/> 
      "<h4>" + spittle.getSpitter().getFullName() + " says...</h4>" +
      "<i>" + spittle.getText() + "</i>" +
  		"</body></html>", true);
  
  ClassPathResource image = new ClassPathResource("spitter_logo_50.png");
  helper.addInline("spitterLogo", image); //<co id="co_addInline"/>
  mailSender.send(message);
}
 
开发者ID:liuxianqiang,项目名称:spring-in-action,代码行数:18,代码来源:SpitterEmailServiceImpl.java

示例2: sendInlineResourceMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * 发送正文中有静态资源(图片)的邮件
 */
@Async("mailAsync")
public void sendInlineResourceMail(String to, String subject, String content, String rscPath,
		String rscId) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		FileSystemResource res = new FileSystemResource(new File(rscPath));
		helper.addInline(rscId, res);

		mailSender.send(message);
		logger.info("嵌入静态资源的邮件已经发送。");
	} catch (MessagingException e) {
		logger.error("发送嵌入静态资源的邮件时发生异常!", e);
	}
}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:24,代码来源:MailUtil.java

示例3: sendInlineResourceMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void sendInlineResourceMail(String to, String subject, String content, String rscPath, String rscId){
    MimeMessage message = mailSender.createMimeMessage();

    try {
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(from);
        helper.setTo(to);
        helper.setSubject(subject);
        helper.setText(content, true);

        FileSystemResource res = new FileSystemResource(new File(rscPath));
        helper.addInline(rscId, res);

        mailSender.send(message);
        log.info("邮件发送成功!");
    } catch (MessagingException e) {
        log.error("邮件发送失败!");
        log.error("失败原因:{}", e);
    }
}
 
开发者ID:jeikerxiao,项目名称:SpringBootStudy,代码行数:22,代码来源:MailServiceImpl.java

示例4: sendInlineMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * 发送带静态资源的邮件
 */
@Test
public void sendInlineMail() {
    MimeMessage message = null;
    try {
        message = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setFrom(Sender);
        helper.setTo(Sender);
        helper.setSubject("主题:带静态资源的邮件");
        //第二个参数指定发送的是HTML格式,同时cid:是固定的写法
        helper.setText("<html><body>带静态资源的邮件内容 图片:<img src='cid:picture' /></body></html>", true);

        FileSystemResource file = new FileSystemResource(new File("src/main/resources/static/image/picture.jpg"));
        helper.addInline("picture", file);
    } catch (Exception e) {
        e.printStackTrace();
    }
    mailSender.send(message);
}
 
开发者ID:zhaoshuxue,项目名称:springBoot,代码行数:23,代码来源:UnitTest.java

示例5: sendInlineMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Test
public void sendInlineMail() throws Exception {

    MimeMessage mimeMessage = mailSender.createMimeMessage();

    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
    helper.setFrom("[email protected]");
    helper.setTo("[email protected]");
    helper.setSubject("主题:嵌入静态资源");
    helper.setText("<html><body><img src=\"cid:weixin\" ></body></html>", true);

    FileSystemResource file = new FileSystemResource(new File("weixin.jpg"));
    helper.addInline("weixin", file);

    mailSender.send(mimeMessage);
}
 
开发者ID:xiaomoinfo,项目名称:SpringBootUnity,代码行数:17,代码来源:MailTests.java

示例6: attachments

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@RequestMapping(value = "attachments", method = RequestMethod.POST, produces = { "application/xml", "application/json" })
public ResponseEntity<Email> attachments(@RequestBody Email email) throws Exception {

	MimeMessage mimeMessage = javaMailSender.createMimeMessage();

	MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
	mimeMessageHelper.setFrom(email.getFrom());
	mimeMessageHelper.setTo(email.getTo());
	mimeMessageHelper.setSubject(email.getSubject());
	mimeMessageHelper.setText("<html><body><img src=\"cid:banner\" >" + email.getText() + "</body></html>", true);

	FileSystemResource file = new FileSystemResource(new File("banner.jpg"));
	mimeMessageHelper.addInline("banner", file);

	FileSystemResource fileSystemResource = new FileSystemResource(new File("Attachment.jpg"));
	mimeMessageHelper.addAttachment("Attachment.jpg", fileSystemResource);

	javaMailSender.send(mimeMessage);
	email.setStatus(true);

	return new ResponseEntity<Email>(email, HttpStatus.OK);
}
 
开发者ID:oscm,项目名称:web,代码行数:23,代码来源:EmailRestController.java

示例7: addResourcesInMessage

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private String addResourcesInMessage(final MimeMessageHelper mailMessage, final String htmlText) throws Exception {
    final Document document = Jsoup.parse(htmlText);

    final List<String> resources = new ArrayList<>();

    final Elements imageElements = document.getElementsByTag("img");
    resources.addAll(imageElements.stream()
            .filter(imageElement -> imageElement.hasAttr("src"))
            .map(imageElement -> {
                final String src = imageElement.attr("src");
                imageElement.attr("src", "cid:" + src);
                return src;
            })
            .collect(Collectors.toList()));

    final String html = document.html();
    mailMessage.setText(html, true);

    for (final String res : resources) {
        final FileSystemResource templateResource = new FileSystemResource(new File(templatesPath, res));
        mailMessage.addInline(res, templateResource, MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(res));
    }

    return html;
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:26,代码来源:EmailServiceImpl.java

示例8: sendTemplatedEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void sendTemplatedEmail(String to, Spittle spittle) 
                                             throws MessagingException {  
  MimeMessage message = mailSender.createMimeMessage();
  MimeMessageHelper helper = new MimeMessageHelper(message, true);

  String spitterName = spittle.getSpitter().getFullName();
  helper.setFrom("[email protected]");
  helper.setTo("[email protected]");
  helper.setSubject("New spittle from " + spitterName);

  //<start id="mergeEmailTemplate"/> 
  Map<String, String> model = new HashMap<String, String>();
  model.put("spitterName", spitterName);
  model.put("spittleText", spittle.getText());
  String emailText = VelocityEngineUtils.mergeTemplateIntoString(
          velocityEngine, "emailTemplate.vm", model );
  //<end id="mergeEmailTemplate"/> 

  //<start id="sendTemplateEmail"/> 
  helper.setText(emailText, true);
  //<end id="sendTemplateEmail"/> 
  
  ClassPathResource image = new ClassPathResource("spitter_logo_50.png");
  helper.addInline("spitterLogo", image); //<co id="co_addInline"/>
  mailSender.send(message);
}
 
开发者ID:liuxianqiang,项目名称:spring-in-action,代码行数:27,代码来源:SpitterEmailServiceImpl.java

示例9: testSendMailWithInlineImage

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Test
public void testSendMailWithInlineImage() throws MessagingException {
    // 建立邮件消息,发送简单邮件和html邮件的区别
    MimeMessage mailMessage = senderImpl.createMimeMessage();
    // 注意这里的boolean,等于真的时候才能嵌套图片,在构建MimeMessageHelper时候,所给定的值是true表示启用,
    // multipart模式
    MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage,
            true);

    // 设置收件人,寄件人
    messageHelper.setTo("[email protected]");
    messageHelper.setFrom("[email protected]");
    messageHelper.setSubject("测试邮件中嵌套图片!!");
    // true 表示启动HTML格式的邮件
    messageHelper.setText(
            "<html><head></head><body><h1>hello!!spring image html mail</h1>"
                    + "<img src=\"cid:aaa\"/></body></html>", true);

    FileSystemResource img = new FileSystemResource(new File(imagePath));

    messageHelper.addInline("aaa", img);

    // 发送邮件
    senderImpl.send(mailMessage);

    System.out.println("邮件发送成功..");
}
 
开发者ID:gukt,项目名称:umbrella,代码行数:28,代码来源:MailTests.java

示例10: sendInlineMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void sendInlineMail() throws Exception {
    MimeMessage mimeMessage = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
    helper.setFrom("[email protected]");
    helper.setTo("[email protected]");
    helper.setSubject("主题:嵌入静态资源");
    helper.setText("<html><body><img src=\"cid:weixin\" ></body></html>", true);
    FileSystemResource file = new FileSystemResource(new File("pom.xml"));
    helper.addInline("weixin", file);
    mailSender.send(mimeMessage);
}
 
开发者ID:nellochen,项目名称:springboot-start,代码行数:12,代码来源:MailTest.java

示例11: send

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void send(String whichMailToSend) throws MessagingException {
    whichMailToSend = "default";

    final MimeMessage mimeMessage = mailSender.createMimeMessage();
    final MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "ISO-2022-JP");

    // TODO: to need to set real data, not test
    final String imageResourceName = new StringBuilder(resourceLoaderPath)
            .append(FILE_SEPARATOR)
            .append("test.jpeg")
            .toString();
    final byte[] imageBytes = new byte[102400];
    final String imageContentType = "image/jpeg";

    // Prepare the evaluation context
    final Context ctx = new Context(LOCALE);
    ctx.setVariable("userName", "dao.name");
    ctx.setVariable("subscriptionDate", new Date());
    ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));
    ctx.setVariable("imageResourceName", imageResourceName); // so that we can reference it from HTML

    // Prepare message using a Spring helper
    mimeMessageHelper.setFrom("[email protected]");
    mimeMessageHelper.setTo("[email protected]");
    mimeMessageHelper.setText("Test English an 日本語", true);  // true = isHtml

    mimeMessage.setSubject("Test English an 日本語", "ISO-2022-JP");

    // Create the HTML body using Thymeleaf
    final String htmlContent = templateEngine.process("test.html", ctx);
    mimeMessageHelper.setText(htmlContent, false);

    // Add the inline image, referenced from the HTML code as "cid:${imageResourceName}"
    final InputStreamSource imageSource = new ByteArrayResource(imageBytes);
    mimeMessageHelper.addInline(imageResourceName, imageSource, imageContentType);

    mailSender.send(mimeMessage);
}
 
开发者ID:edydkim,项目名称:MQMail,代码行数:40,代码来源:MailServiceImpl.java

示例12: _createMailMessageUsingVelocity

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private MimeMessagePreparator _createMailMessageUsingVelocity() {
       MimeMessagePreparator preparator = new MimeMessagePreparator() {
       											@Override
									            public void prepare(MimeMessage mimeMessage) throws Exception {
									                MimeMessageHelper message = new MimeMessageHelper(mimeMessage,
									                												  true);	// multi-part!!
									                
									                message.setTo("[email protected]");
									                message.setFrom("[email protected]"); 
									                message.setSubject("Test!!!");
									                
									                // Text... using velocity
									                Map<String,Object> model = new HashMap<String,Object>();
									                model.put("user",new User("Alex","[email protected]"));
									                String text = VelocityEngineUtils.mergeTemplateIntoString(_velocityEngine,
									                														  "template.vm",
									                														  Charsets.ISO_8859_1.name(),
									                														  model);
									                message.setText(text, true);
									                
									                // Image
									                ClassPathResource res = new ClassPathResource("logo.gif");
									                message.addInline("logoOpenData", res);											               											                
									            }
       };
       return preparator;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:28,代码来源:GuiceSpringTest.java

示例13: sendMailWithInline

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
	 * Send HTML mail with inline image
	 */
	public void sendMailWithInline(final String recipientName, final String recipientEmail, final Locale locale)
			throws MessagingException {

		// Prepare the evaluation context
		final Context ctx = new Context(locale);
		ctx.setVariable("name", recipientName);
		ctx.setVariable("subscriptionDate", new Date());
		ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));

		// Prepare message using a Spring helper
		final MimeMessage mimeMessage = mailSender.createMimeMessage();
		final MimeMessageHelper message
				= new MimeMessageHelper(mimeMessage, true /* multipart */, "UTF-8");
		message.setSubject("Example HTML email with inline image");
		message.setFrom("[email protected]");
		message.setTo(recipientEmail);

		// Create the HTML body using Thymeleaf
		final String htmlContent = htmlTemplateEngine.process("mail/email-inlineimage", ctx);
		message.setText(htmlContent, true /* isHtml */);

		// Add the inline image, referenced from the HTML code as "cid:${imageResourceName}"
//		final InputStreamSource imageSource = new ByteArrayResource(imageBytes);
//		message.addInline(imageResourceName, imageSource, imageContentType);
		message.addInline("sample-image", new ClassPathResource("public/images/logo_type_A_en.png"), "image/png");

		// Send mail
		mailSender.send(mimeMessage);
	}
 
开发者ID:JakduK,项目名称:jakduk-api,代码行数:33,代码来源:EmailService.java

示例14: sendMessage

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void sendMessage(String emailFrom, String emailTo, String subject, String template, HashMap<String, Object> staticResources, HashMap<String, Object> dynamicResources) throws Exception {		
	String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template, "UTF-8", dynamicResources);
	
       // configure mail helper
	MimeMessage message = javaMailSender.createMimeMessage();
	MimeMessageHelper helper = new MimeMessageHelper(message, true); // configure multipart email configuration: css and images inside
	helper.setFrom(emailFrom);
	helper.setTo(emailTo);
	helper.setSubject(subject);
	helper.setText(text, true); // configure html email
	
	Iterator<String> iter = staticResources.keySet().iterator();
	while(iter.hasNext()) {
		String key = (String)iter.next();
	    InputStreamSource val = (InputStreamSource)staticResources.get(key);
	    
	    helper.addInline(key, val, "text/html");
	}
	
	// send message in OSGi envirotment
       ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
       try {
        Thread.currentThread().setContextClassLoader(javax.mail.Session.class.getClassLoader());
		javaMailSender.send(message);
       }
	catch (Exception e) {
		throw new Exception(e);
	} finally {
		Thread.currentThread().setContextClassLoader(oldClassLoader);
	}
}
 
开发者ID:thingtrack,项目名称:konekti,代码行数:33,代码来源:MailServiceImpl.java

示例15: addInlineResource

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private void addInlineResource(MimeMessageHelper messageHelper, String resourcePath, String resourceIdentifier) throws MessagingException {
    Resource resource = new ClassPathResource(resourcePath);
    messageHelper.addInline(resourceIdentifier, resource);
}
 
开发者ID:iainporter,项目名称:oauth2-provider,代码行数:5,代码来源:MailSenderServiceImpl.java


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