<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    mashiguang

    小馬快跑

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      20 隨筆 :: 0 文章 :: 60 評論 :: 0 Trackbacks

    使用commons mail時需要的jar包:
    1,commons-email-1.1.jar
    2,mail.jar
    3,activation.jar
    (在web應用里只需要commons-email包)

    發送簡單的文字郵件:

    SimpleEmail email = new SimpleEmail();

    email.setHostName(
    "smtp.sina.com");
    email.setAuthentication(
    "username""password");//在郵件服務商處注冊的用戶名和密碼
    email.addTo("mailTo@163.com");
    email.setFrom(
    "username@sina.com""alias");

    email.setCharset(
    "UTF-8");//gbk或gb2312,只要支持中文就行
    email.setSubject("title");
    email.setMsg(
    "content");
    email.send();

    發送帶附件的郵件:
    // Create the attachment
    EmailAttachment attachment = new EmailAttachment();
    attachment.setPath(
    "mypictures/john.jpg");
    attachment.setDisposition(EmailAttachment.ATTACHMENT);
    attachment.setDescription(
    "Picture of John");
    attachment.setName(
    "John");

    // Create the email message
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName(
    "mail.myserver.com");
    email.setAuthentication(
    "username""password");
    email.addTo(
    "jdoe@somewhere.org""John Doe");
    email.setFrom(
    "me@apache.org""Me");
    email.setCharset(
    "UTF-8");
    email.setSubject(
    "The picture");
    email.setMsg(
    "Here is the picture you wanted");

    // add the attachment
    email.attach(attachment);

    // send the email
    email.send();

    創建多個EmailAttachment對象,并調用MultiPartEmail.attach();就可以發送多個附件.

    發送HTML格式的郵件:

    發送html格式的郵件和簡單郵件的區別就在創建HtmlEmail對象
    并用email.setHtmlMsg(String)或email.setMsg(String)把含有html標簽的字符串賦給email對象.
    HtmlEmail對象還有一個setTextMsg(String)方法,這個方法參數里的html標簽會被當做普通字符處理,不會被解析成html元素.
    更詳細內容可以看apache commons-email的用戶指南.

    posted on 2007-11-01 16:51 mashiguang 閱讀(1528) 評論(4)  編輯  收藏 所屬分類: java web開發

    評論

    # re: apache commons-email 2007-11-01 16:54 mashiguang
    在使用中碰到的問題:
    發送HTML格式的郵件時同時發送附件的話,郵件內容會被當作附件處理,也就是說如果你發了兩個附件和一篇HTML格式的正文,收件人會收到三個附件,前兩個是正常的附件,HTML格式的正文變成了第三個附件,碰到同樣問題的朋友請指點.   回復  更多評論
      

    # re: apache commons-email 2007-12-20 15:02 fasdf
    fasdfasdfasdfsadf  回復  更多評論
      

    # re: apache commons-email 2008-01-02 15:21 ajax_milan
    文中提到的發送中文的方法不行,建議使用如下方法:
    1.去掉email.setCharset("UTF-8");
    2.不使用email.setMsg("Here is the picture you wanted");
    3.使用email.setContent("這是一個測試","text/plain;charset=GBK");  回復  更多評論
      

    # re: apache commons-email[未登錄] 2014-06-17 10:57 w
    setMsg和setHtmlMsg有什么區別啊?  回復  更多評論
      

    主站蜘蛛池模板: 成年大片免费高清在线看黄| 亚洲熟伦熟女专区hd高清| 永久免费观看黄网站| 免费v片视频在线观看视频| 久久无码av亚洲精品色午夜| 美女被免费视频网站a国产| 亚洲精华国产精华精华液网站| 全免费a级毛片免费**视频| 欧洲亚洲国产精华液| 国产人妖ts在线观看免费视频| 无码一区二区三区亚洲人妻| www.亚洲一区| 精品国产污污免费网站| 亚洲黄色一级毛片| 无码国产精品久久一区免费| 亚洲欧美日韩中文无线码| 亚洲av中文无码| 在线观看人成视频免费无遮挡 | 国产免费AV片无码永久免费| 激情小说亚洲图片| 国产亚洲大尺度无码无码专线| 成年女人A毛片免费视频| 亚洲欧洲自拍拍偷午夜色| 在线观看免费人成视频色9| 国产亚洲Av综合人人澡精品| 中文亚洲AV片在线观看不卡| 日本免费污片中国特一级| 亚洲精品一卡2卡3卡三卡四卡| 啦啦啦中文在线观看电视剧免费版| 亚洲国产精品久久久久秋霞小| 亚洲国产精品成人网址天堂| 久久精品国产免费一区| 亚洲国产最大av| 中文字幕亚洲综合久久男男| 亚洲人成免费网站| 黄色毛片免费观看| 亚洲一区二区在线免费观看| 永久久久免费浮力影院| 日本免费人成网ww555在线| 亚洲日韩AV一区二区三区四区| 中文字幕亚洲综合久久菠萝蜜 |