package be.ac.fundp.infonet.util;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
/**
* This class offers SMTP features. It uses the SUN JavaMail API.<BR>
* Convenient methods are provided for simple mail. Here is a typical use of this class for
* sending a more elaborated mail:<BR>
* <p>
* <code>
* Message msg = Mail.initMessage(from, userName, to, theSubject, mailServer);<BR>
* Multipart body = Mail.setMessage("Hello. This is a simple mail");<BR>
* body = Mail.addAttachment(body, new File("/home/me/xml/content.xml"));<BR>
* body = Mail.addAttachment(body, "/home/me/xml/content2.xml");<BR>
* Mail.send(msg, body);<BR>
* </code>
* </p>
* @author Stephane Nicoll - Devoteam
* @version 0.4
*/
public class Mail {
/**
* Posts a mail with the specified parameter in plain text.
* @param from
* The sender's e-mail address
* @param userNamr
* The user's name (which will be set as the sender of the mail)
* @param to
* The receiver's e-mail address
* @param subject
* The subject of the mail
* @param message
* The message to send
* @param mailServer
* The address of the SMTP server to use
* @see javax.mail.SendFailedException SendFailedException - For more details about exception handling
*/
public static void postMail(String from, String userName, String to,
String subject, String message, String mailServer)
throws MessagingException, SendFailedException, UnsupportedEncodingException
{
Message msg = initMessage(from, userName, to, subject, mailServer);
if (msg != null)
{
msg.setContent(message, "text/plain");
Transport.send(msg);
}
}
/**
* Posts a mail with the specified parameter in plain text.
* @param from
* The sender's e-mail address
* @param userNamr
* The user's name (which will be set as the sender of the mail)
* @param to
* The receiver's e-mail address
* @param subject
* The subject of the mail
* @param message
* The message to send, contained in a file
* @param mailServer
* The address of the SMTP server to use
* @see javax.mail.SendFailedException SendFailedException - For more details about exception handling
*/
public static void postMail(String from, String userName, String to,
String subject, File message, String mailServer)
throws MessagingException, SendFailedException, UnsupportedEncodingException
{
Message msg = initMessage(from, userName, to, subject, mailServer);
if (msg != null)
{
try
{
String res = loadFile(message);
msg.setContent(res, "text/plain");
Transport.send(msg);
}
catch (IOException ie)
{
throw new MessagingException("An error occured while loading the file's content");
}
}
}
/**
* Posts a mail with the specified parameter in HTML.
* @param from
* The sender's e-mail address
* @param userName
* The user's name (which will be set as the sender of the mail)
* @param to
* The receiver's e-mail address
* @param subject
* The subject of the mail
* @param message
* The message to send
* @param mailServer
* The address of the SMTP server to use
* @see javax.mail.SendFailedException SendFailedException - For more details about exception handling
*/
public static void postHTMLMail(String from, String userName, String to,
String subject, String message, String mailServer)
throws MessagingException, SendFailedException, UnsupportedEncodingException
{
Message msg = initMessage(from, userName, to, subject, mailServer);
if (msg != null)
{
msg.setContent(message, "text/html");
msg.setDisposition(Part.INLINE);
Transport.send(msg);
}
}
/**
* Posts a mail with the specified parameter in HTML.
* @param from
* The sender's e-mail address
* @param userName
* The user's name (which will be set as the sender of the mail)
* @param to
* The receiver's e-mail address
* @param subject
* The subject of the mail
* @param message
* The HTML message to send, contained in a file
* @param mailServer
* The address of the SMTP server to use
* @see javax.mail.SendFailedException SendFailedException - For more details about exception handling
*/
public static void postHTMLMail(String from, String userName, String to,
String subject, File message, String mailServer)
throws MessagingException, SendFailedException, UnsupportedEncodingException
{
Message msg = initMessage(from, userName, to, subject, mailServer);
if (msg != null)
{
try
{
String res = loadFile(message);
msg.setContent(res, "text/html");
msg.setDisposition(Part.INLINE);
Transport.send(msg);
}
catch (IOException ie)
{
throw new MessagingException("An error occured while loading the file's content");
}
}
}
/**
* Initializes a new Message with the specified parameters.
* @param from
* The sender's e-mail address
* @param userNamr
* The user's name (which will be set as the sender of the mail)
* @param to
* The receiver's e-mail address
* @param subject
* The subject of the mail
* @param mailServer
* The address of the SMTP server to use
* @return a new intialized Message
*/
public static Message initMessage(String from, String userName, String to,
String subject, String mailServer)
throws MessagingException, UnsupportedEncodingException
{
Properties props = new Properties();
props.put("mail.smtp.host", mailServer);
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
addressFrom.setPersonal(userName);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[1];
addressTo[0] = new InternetAddress(to);
msg.setRecipients(Message.RecipientType.TO, addressTo);
msg.setSubject(subject);
return msg;
}
/**
* Sets the given String as this multi part's content with a MIME type of "text/plain".
* @param m
* The multi part
* @param message
* A string representation of the message
* @throw MessagingException
* If the underlying implementation does not support modification of existing values
* @throw IllegalStateException
* If the multi part is not intialized properly
* @return the multi part modified
*/
public static Multipart setMessage(Multipart m, String message)
throws MessagingException, IllegalStateException
{
if (m == null)
{
throw new IllegalStateException("null value is not allowed");
}
MimeBodyPart mb = new MimeBodyPart();
mb.setText(message);
m.addBodyPart(mb);
return m;
}
/**
* Sets the given String as this multi part's content with a MIME type of "text/html".
* @param m
* The multi part
* @param message
* A string representation of the HTML message
* @throw MessagingException
* If the underlying implementation does not support modification of existing values
* @throw IllegalStateException
* If the multi part is not intialized properly
* @return the multi part modified
*/
public static Multipart setHTMLMessage(Multipart m, String message)
throws MessagingException, IllegalStateException
{
if (m == null)
{
throw new IllegalStateException("null value is not allowed");
}
MimeBodyPart mb = new MimeBodyPart();
mb.setContent
没有合适的资源?快使用搜索试试~ 我知道了~
eConf是一个开源利用Java开发的e-learning软件.
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共63个文件
java:62个
copying:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
![star](https://csdnimg.cn/release/downloadcmsfe/public/img/star.98a08eaa.png)
温馨提示
eConf是一个开源利用Java开发的e-learning软件.它可以容易地记录web会议并可用于记录多台电脑上的科学课程。eConf是一个HTTP代理服务器的附件能够捕获在会议期间显示的Web页面并记录下发表人的声音,声音与web页面将被同步以便学生能够听到被记录的课程。eConf当前的版本是构建在W3C的Jigsaw代理服务器上,但也允许使用其它代理服务器。eConf需要java1.3以上的虚拟机与Java多媒体框架(JMF).
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 63 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
- wildfireCYH2012-11-23还不错,是我想要的资料
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
ChristSnow
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 打包和分发Rust工具.pdf
- SQL中的CREATE LOGFILE GROUP 语句.pdf
- C语言-leetcode题解之第172题阶乘后的零.zip
- C语言-leetcode题解之第171题Excel列表序号.zip
- C语言-leetcode题解之第169题多数元素.zip
- ocr-图像识别资源ocr-图像识别资源
- 图像识别:基于Resnet50 + VGG16模型融合的人体细胞癌症分类模型实现-图像识别资源
- C语言-leetcode题解之第168题Excel列表名称.zip
- C语言-leetcode题解之第167题两数之和II-输入有序数组.zip
- C语言-leetcode题解之第166题分数到小数.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)