org.apache.commons.mail.HtmlEmail.embed()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.apache.commons.mail.HtmlEmail.embed()方法的一些代码示例,展示了HtmlEmail.embed()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HtmlEmail.embed()方法的具体详情如下:
包路径:org.apache.commons.mail.HtmlEmail
类名称:HtmlEmail
方法名:embed

HtmlEmail.embed介绍

[英]Embeds a file in the HTML. This implementation delegates to #embed(File,String).
[中]在HTML中嵌入一个文件。此实现委托#嵌入(文件、字符串)。

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Embeds a file in the HTML. This implementation delegates to
 * {@link #embed(File, String)}.
 *
 * @param file The <code>File</code> object to embed
 * @return A String with the Content-ID of the file.
 * @throws EmailException when the supplied <code>File</code> cannot be
 * used; also see {@link javax.mail.internet.MimeBodyPart} for definitions
 *
 * @see #embed(File, String)
 * @since 1.1
 */
public String embed(final File file) throws EmailException
{
  final String cid = EmailUtils.randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase(Locale.ENGLISH);
  return embed(file, cid);
}

代码示例来源:origin: camunda/camunda-bpm-platform

/**
 * Attempts to parse the specified <code>String</code> as a URL that will
 * then be embedded in the message.
 *
 * @param urlString String representation of the URL.
 * @param name The name that will be set in the filename header field.
 * @return A String with the Content-ID of the URL.
 * @throws EmailException when URL supplied is invalid or if {@code name} is null
 * or empty; also see {@link javax.mail.internet.MimeBodyPart} for definitions
 *
 * @see #embed(URL, String)
 * @since 1.1
 */
public String embed(final String urlString, final String name) throws EmailException
{
  try
  {
    return embed(new URL(urlString), name);
  }
  catch (final MalformedURLException e)
  {
    throw new EmailException("Invalid URL", e);
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

return embed(dataSource, name, cid);

代码示例来源:origin: camunda/camunda-bpm-platform

return embed(new FileDataSource(file), file.getName(), cid);

代码示例来源:origin: camunda/camunda-bpm-platform

return embed(new URLDataSource(url), name);

代码示例来源:origin: stackoverflow.com

StringBuffer msg = new StringBuffer();
 msg.append("<html><body>");
 msg.append("<img src=cid:").append(he.embed(img)).append(">");
 msg.append("<img src=cid:").append(he.embed(png)).append(">");
 msg.append("</body></html>");
 HtmlEmail he = new HtmlEmail();
he.setHtmlMsg(msg.toString());

代码示例来源:origin: br.com.caelum.vraptor/vraptor-simplemail

protected void addEmbeddables(HtmlEmail email) throws EmailException {
  for(Entry<String,DataSource> entry : toEmbed.entrySet()){
    String key = entry.getKey();
    String cid = email.embed(entry.getValue(),key);
    with(key, "cid:" + cid);
  }
}

代码示例来源:origin: org.apache.commons/commons-email

/**
 * Embeds a file in the HTML. This implementation delegates to
 * {@link #embed(File, String)}.
 *
 * @param file The <code>File</code> object to embed
 * @return A String with the Content-ID of the file.
 * @throws EmailException when the supplied <code>File</code> cannot be
 * used; also see {@link javax.mail.internet.MimeBodyPart} for definitions
 *
 * @see #embed(File, String)
 * @since 1.1
 */
public String embed(final File file) throws EmailException
{
  final String cid = EmailUtils.randomAlphabetic(HtmlEmail.CID_LENGTH).toLowerCase(Locale.ENGLISH);
  return embed(file, cid);
}

代码示例来源:origin: org.apache.commons/commons-email

/**
 * Attempts to parse the specified <code>String</code> as a URL that will
 * then be embedded in the message.
 *
 * @param urlString String representation of the URL.
 * @param name The name that will be set in the filename header field.
 * @return A String with the Content-ID of the URL.
 * @throws EmailException when URL supplied is invalid or if {@code name} is null
 * or empty; also see {@link javax.mail.internet.MimeBodyPart} for definitions
 *
 * @see #embed(URL, String)
 * @since 1.1
 */
public String embed(final String urlString, final String name) throws EmailException
{
  try
  {
    return embed(new URL(urlString), name);
  }
  catch (final MalformedURLException e)
  {
    throw new EmailException("Invalid URL", e);
  }
}

代码示例来源:origin: stackoverflow.com

HtmlEmail email = new ImageHtmlEmail();
email.setHostName("mail.myserver.com");
email.addTo("jdoe@somewhere.org", "John Doe");
email.setFrom("me@apache.org", "Me");
email.setSubject("Test email with inline image");
// embed the image and get the content id
URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
String cid = email.embed(url, "Apache logo");
// set the html message
email.setHtmlMsg(htmlEmailTemplate, new File("").toURI().toURL(), false);

代码示例来源:origin: org.apache.commons/commons-email

return embed(dataSource, name, cid);

代码示例来源:origin: org.apache.commons/commons-email

return embed(new FileDataSource(file), file.getName(), cid);

代码示例来源:origin: org.apache.commons/commons-email

return embed(new URLDataSource(url), name);

代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play

if (inlineEmbeds != null) {
  for (Map.Entry<String, InlineImage> entry : inlineEmbeds.entrySet()) {
    htmlEmail.embed(entry.getValue().getDataSource(), entry.getKey(), entry.getValue().getCid());

代码示例来源:origin: biezhi/java-library-examples

public static void main(String[] args) throws EmailException, MalformedURLException {
    // 创建 Email Message
    HtmlEmail email = new HtmlEmail();
    email.setHostName("mail.myserver.com");
    email.addTo("jdoe@somewhere.org", "John Doe");
    email.setFrom("me@apache.org", "Me");
    email.setSubject("Test email with inline image");

    // 嵌入图片
    URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
    String cid = email.embed(url, "Apache logo");

    // 发送 HTML 内容
    email.setHtmlMsg("<html>The apache logo - <img src=\"cid:"+cid+"\"></html>");

    // 设置替代消息
    email.setTextMsg("Your email client does not support HTML messages");

    // 发送
    email.send();
  }
}

代码示例来源:origin: org.apache.commons/commons-email

private void assertCorrectContentType(final String picture, final String contentType) throws Exception {
  final HtmlEmail htmlEmail = createDefaultHtmlEmail();
  final String cid = htmlEmail.embed(new File("./src/test/resources/images/" + picture), "Apache Logo");
  final String htmlMsg = "<html><img src=\"cid:" + cid + "\"><html>";
  htmlEmail.setHtmlMsg(htmlMsg);
  htmlEmail.buildMimeMessage();
  final MimeMessage mm = htmlEmail.getMimeMessage();
  mm.saveChanges();
  final MimeMessageParser mmp = new MimeMessageParser(mm);
  mmp.parse();
  final List<?> attachments = mmp.getAttachmentList();
  assertEquals("Attachment size", 1, attachments.size());
  final DataSource ds = (DataSource) attachments.get(0);
  assertEquals("Content type", contentType, ds.getContentType());
}

代码示例来源:origin: stackoverflow.com

ValueMap props = ResourceUtil.getValueMap(resource);
 HtmlEmail email = new HtmlEmail();
 String[] mailTo = props.get("mailto", new String[0]);
 email.setFrom((String)props.get("from"));
   for (String toAddr : mailTo) {
     email.addTo(toAddr);
  }
 //========Email Attachments===============
 for (Map.Entry<String, RequestParameter[]> param : slingRequest.getRequestParameterMap().entrySet()) {
   RequestParameter rpm = param.getValue()[0];
   if(!rpm.isFormField()) {
     EmailAttachment attachment = new EmailAttachment();
     attachment.setPath(rpm.getFileName());
     attachment.setDisposition(EmailAttachment.ATTACHMENT);
     attachment.setDescription("Any Description");
     attachment.setName("Any name you can set");
     email.embed(new ByteArrayDataSource(rpm.get(), rpm.getContentType()), rpm.getFileName());
   }
 }
 //========Email Attachment END===========
 String emailTextToSend = "<p>Name: " + slingRequest.getParameter("name") + "</p>";
 emailTextToSend += "<p>Message: " + slingRequest.getParameter("message") + "</p>";
 email.setHtmlMsg(emailTextToSend);
 email.setSubject((String)props.get("subject"));
 MessageGatewayService messageGatewayService = sling.getService(MessageGatewayService.class);
 MessageGateway messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
 messageGateway.send(email);

代码示例来源:origin: org.apache.commons/commons-email

cid = htmlEmail3.embed(imageFile, "Apache Logo");
cid = htmlEmail4.embed(imageFile, "Apache Logo");
htmlMsg = "<html><b>This is a HTML message with an inline image - <img src=\"cid:" + cid + "\"> and attachment</b><html>";

代码示例来源:origin: ManyDesigns/Portofino

} else {
  FileDataSource dataSource = new FileDataSource(new File(attachment.getFilePath()));
  htmlEmail.embed(dataSource, attachment.getName(), attachment.getContentId());

相关文章