apache-comnons系列之commons-email1.4 学习笔记

原创 2017年07月29日 23:56:01

apache-comnons系列之commons-email1.4 学习笔记

概述

Email

  • The base class for all email messages. This class sets the
  • sender’s email & name, receiver’s email & name, subject, and the sent date.
  • Subclasses are responsible for setting the message body.

SimpleEmail

  • This class is used to send simple internet email messages without attachments.

MultiPartEmail

  • A multipart email.This class is used to send multi-part internet email like messages with attachments.
  • To create a multi-part email, call the default constructor and then you can call setMsg() to set the message and call the different attach() methods.

EmailAttachment

  • This class models an email attachment. Used by MultiPartEmail.
HtmlEmail
  • An HTML multipart email.
  • This class is used to send HTML formatted email. A text message can also be set for HTML unaware email clients, such as text-based email clients.
ImageHtmlEmail
  • Small wrapper class on top of HtmlEmail which encapsulates the required logic to retrieve images that are contained in “<img src=../>” elements in the HTML
  • code. This is done by replacing all img-src-elements with “cid:”-entries and embedding images in the email.

EmailUtils

  • Utility methods used by commons-email.

测试

  • org.apache.commons.mail.EmailTest
    • MimeMessage message—-The email message to send.
    • Object content—-The content.
    • MimeMultipart emailBody—-An attachment
    • send
      • Sends the email. Internally we build a MimeMessage which is afterwards sent to the SMTP server.
    • buildMimeMessage
      • Does the work of actually building the MimeMessage. Please note that a user rarely calls this method directly and only if he/she is interested in the sending the underlying MimeMessage without commons-email.
      • this.message = this.createMimeMessage(this.getMailSession());
      • if (this.content != null)—-else if (this.emailBody != null)
    • sendMimeMessage
      • Sends the previously created MimeMessage to the SMTP server.
      • Transport.send(this.message);
  • org.apache.commons.mail.MultiPartEmailTest
    • MimeMultipart container—-Body portion of the email
    • BodyPart primaryBodyPart—The message container.
    • boolean initialized
    • init
      • Initialize the multipart email.
      • container = createMimeMultipart();
      • super.setContent(container);
      • this.emailBody = aMimeMultipart;
    • setMsg
      • Set the message of the email.
      • final BodyPart primary = getPrimaryBodyPart();
    • getPrimaryBodyPart
      • primaryBodyPart = createBodyPart();
      • getContainer().addBodyPart(primaryBodyPart, 0);
    • attach
      • Attach a file.
      • final BodyPart bodyPart = createBodyPart();
      • bodyPart.setDataHandler(new DataHandler(ds));
      • getContainer().addBodyPart(bodyPart);
    • buildMimeMessage
      • Does the work of actually building the MimeMessage. Please note that a user rarely calls this method directly and only if he/she is interested in the sending the underlying MimeMessage without commons-email.
      • final BodyPart body = this.getPrimaryBodyPart();
      • super.buildMimeMessage();—-这里与init时候的super.setContent(container);呼应上
  • org.apache.commons.mail.HtmlEmailTest
    • String text
      • Text part of the message. This will be used as alternative text if the email client does not support HTML messages.
    • String html
      • Html part of the message.
    • inlineEmbeds = new HashMap String, InlineImage ();
      • Embedded images Map where the key is the user-defined image name.
    • embed
      • Attempts to parse the specified String as a URL that will then be embedded in the message.
      • final MimeBodyPart mbp = new MimeBodyPart();
      • mbp.setDataHandler(new DataHandler(dataSource));
      • final InlineImage ii = new InlineImage(encodedCid, dataSource, mbp);
      • this.inlineEmbeds.put(name, ii);
    • build
      • bodyContainer.addBodyPart(msgHtml, 0);
      • bodyEmbedsContainer.addBodyPart(image.getMbp());
      • bodyContainer.addBodyPart(msgText, 0);
  • org.apache.commons.mail.ImageHtmlEmailTest
    • REGEX_IMG_SRC—-Regexp for extracting tags
    • REGEX_SCRIPT_SRC–regexp for extracting tags
    • String temp = replacePattern(super.html, IMG_PATTERN);
    • temp = replacePattern(temp, SCRIPT_PATTERN);
    • setHtmlMsg(temp);
版权声明:本文为博主原创文章,未经博主允许不得转载。

Apache Commons Math3学习笔记(1)- 快速傅立叶变换

傅立叶变换:org.apache.commons.math3.transform.FastFourierTransformer类。 用法示例代码: double inputData = new d...
  • kingfox
  • kingfox
  • 2015年03月07日 17:14
  • 4819

Commons Math学习笔记

先列出一个目录:(这个目录是根据commons math 2.1库的结构设计的) Section 1 linear 线性代数(矩阵为主) 1) Vector 向量 2) Matrix...
  • jiutianhe
  • jiutianhe
  • 2014年11月21日 15:37
  • 13821

Apache Commons Math3学习笔记(3) - 数值积分

Apache.Commons.Math3里面的数值积分支持类采用的是“逼近法”,即,先对大区间做一次积分,再对小区间做一次积分,若两次积分结果的差值小于某一设定的误差值,则认为积分完成。否则,将区间再...
  • kingfox
  • kingfox
  • 2015年03月09日 13:13
  • 4843

apache-comnons系列之commons-vfs2 学习笔记

apache-comnons系列之commons-vfs2 学习笔记概述 参考 http://p7engqingyang.iteye.com/blog/1702429 http://blog.csd...
  • undergrowth
  • undergrowth
  • 2017年08月09日 00:30
  • 453

apache-comnons系列之commons-net3.6 学习笔记

apache-comnons系列之commons-net3.6 学习笔记概述SocketClient The SocketClient provides the basic operations th...
  • undergrowth
  • undergrowth
  • 2017年07月30日 22:46
  • 515

apache-comnons系列之commons-logging1.2 学习笔记

apache-comnons系列之commons-logging1.2 学习笔记概述 参考 http://blog.csdn.net/linshuhe1/article/details/537615...
  • undergrowth
  • undergrowth
  • 2017年08月06日 14:29
  • 163

apache-comnons系列之commons-pool2.4 学习笔记

apache-comnons系列之commons-pool2.4 学习笔记概述 参考 http://www.jianshu.com/p/b0189e01de35 https://my.oschina...
  • undergrowth
  • undergrowth
  • 2017年07月29日 16:14
  • 234

apache-comnons系列之commons-configuration2 学习笔记

apache-comnons系列之commons-configuration2 学习笔记概述 参考 http://blog.csdn.net/werder/article/details/54562...
  • undergrowth
  • undergrowth
  • 2017年08月05日 21:18
  • 673

apache-comnons系列之commons-dbutils1.7 学习笔记

apache-comnons系列之commons-dbutils1.7 学习笔记概述 参考 http://blog.csdn.net/imust_can/article/details/700597...
  • undergrowth
  • undergrowth
  • 2017年07月26日 00:17
  • 514

apache commons学习系列之Email组件

基于commons Email version 1.3 主要类:   SimpleEmail - This class is used to send basic text based email...
  • xby1993
  • xby1993
  • 2014年04月14日 14:21
  • 992
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:apache-comnons系列之commons-email1.4 学习笔记
举报原因:
原因补充:

(最多只允许输入30个字)