2. 基于 JavaMail 邮件系统的设计与实现
摘 要
本论文阐述了 Web 邮件系统所涉及的几个重要协议,对 JavaMail API 核心类进行了介
绍,并给出了其中发送邮件功能的详细设计过程。JavaMail 结合 JSP 的结构化特性,易于实
现灵活高效、方便移植的 Web 邮件应用程序。
关键词:文本邮件;HTML 邮件;带附件邮件;JavaMail
3. Design and Implementation of Mail System Based on
JavaMail
Abstract
This paper first expatiated on some protocols come down to the Web mail system , and then
introduced the architecture and core classes of JavaMail API. After that , the articlepresented the
system framework and the detailed design process of mail sending. In conclusion , it can easily
implement flexible , high effective and transplantable Web mail applications with JavaMail and
structured JSP.
Keywords:text mail;html mail;attachment mail;javamail
18. 图 6 使用 Foxmail 查看文本邮件
4.1.3 Html 邮件发送
发送 Html 邮件跟发送 Text 邮件没有太大的不同,创建邮件的时候稍微有所
区别,其他各部分的操作都是相同。只需要调用 setContent()方法,把 content 设
置为:”text/html”。因此,我们在 Html 页面添加一个 select,当用户选择以 Html
格式发送时,type 就为 html,邮件将以 Html 格式发送。
htmlmail.html sendhtmlmail.jsp
其登陆窗口和用户数据如下图(图):
19. 图 7 HTML 邮件发送用户信息输入页面
sendhtmlmail.jsp 主要代码如下:
String type = request.getParameter("type");
获取邮件发送的类型。
message.setContent(text,type+";charset=GB2312");
置邮件发送的类型,若 type 属性为“text/plain” 则邮件以文本格式发送。若
,
type 属性为“text/html” 则邮件以 HTML 格式发送。
,
点击发送邮件,此时结果如图:
图 8 HTML e-mail 的发送