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

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

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

    mashiguang

    小馬快跑

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

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

    發(fā)送簡單的文字郵件:

    SimpleEmail email = new SimpleEmail();

    email.setHostName(
    "smtp.sina.com");
    email.setAuthentication(
    "username""password");//在郵件服務(wù)商處注冊的用戶名和密碼
    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();

    發(fā)送帶附件的郵件:
    // 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();

    創(chuàng)建多個EmailAttachment對象,并調(diào)用MultiPartEmail.attach();就可以發(fā)送多個附件.

    發(fā)送HTML格式的郵件:

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

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

    評論

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

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

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

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

    主站蜘蛛池模板: 亚洲AV成人精品日韩一区| 免费国产污网站在线观看| 日本中文字幕免费看| 精品国产一区二区三区免费看| 成年女人视频网站免费m| 亚洲欧洲国产成人精品| 91免费国产自产地址入| 亚洲人成电影在线观看网| 久九九精品免费视频| 亚洲日本成本人观看| 国产免费av片在线无码免费看| 精品国产日韩亚洲一区91| 亚洲精品麻豆av| 中文字幕无码免费久久9一区9 | 亚洲男人第一无码aⅴ网站 | 大桥未久亚洲无av码在线| 免费a级毛片大学生免费观看| 黄色毛片免费在线观看| 久久久久亚洲精品男人的天堂| 在线观看片免费人成视频播放| 久久精品国产精品亚洲艾草网| 日本高清在线免费| 亚洲a∨国产av综合av下载| 亚洲国产精品自产在线播放| 亚洲伊人久久大香线焦| 影音先锋在线免费观看| 羞羞的视频在线免费观看| 曰韩亚洲av人人夜夜澡人人爽 | 亚洲自偷自拍另类图片二区| 德国女人一级毛片免费| 国产免费内射又粗又爽密桃视频 | 亚洲精品无码久久久久APP| 一级毛片直播亚洲| 亚洲精品无码专区久久| 亚洲人成人网站在线观看| 久久免费精彩视频| 亚洲精品无码永久在线观看男男| 亚洲精品美女久久久久99小说| 麻花传媒剧在线mv免费观看| 亚洲男人都懂得羞羞网站| 日本成人免费在线|