當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。