首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

用commons-email-1.2.jar兑现发邮件功能

2012-11-23 
用commons-email-1.2.jar实现发邮件功能从http://commons.apache.org/email/download_email.cgi下载最新的

用commons-email-1.2.jar实现发邮件功能

从http://commons.apache.org/email/download_email.cgi下载最新的Common Email,版本1.2。

?

?

TestCommonEMail类

?

package org.mail.test;import org.apache.commons.mail.EmailAttachment;import org.apache.commons.mail.EmailException;import org.apache.commons.mail.MultiPartEmail;import org.apache.commons.mail.SimpleEmail;public class TestCommonEMail {public static void main(String[] args) {MultiPartEmail email = new MultiPartEmail();email.setHostName("smtp.qq.com");// 设置使用发电子邮件的邮件服务器  smtp.163.comtry {email.addTo("收件人信箱", "收件人别名");email.setAuthentication("发件人信箱", "发件人信箱密码");//smtp认证的用户名和密码email.setFrom("发件人信箱", "发件人别名");//写的信箱要与设置使用发电子邮件的邮件服务器相对应email.setSubject("Test apache.commons.mail message");//标题email.setMsg("This is a simple test of commons-email");//内容EmailAttachment emailattachment = new EmailAttachment();emailattachment.setPath("love.jpg");//放到工程下email.attach(emailattachment);email.send();} catch (EmailException ex) {ex.printStackTrace();}}}
??

?

热点排行
Bad Request.