<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 評(píng)論 :: 0 Trackbacks

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

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

    SimpleEmail email = new SimpleEmail();

    email.setHostName(
    "smtp.sina.com");
    email.setAuthentication(
    "username""password");//在郵件服務(wù)商處注冊(cè)的用戶名和密碼
    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)建多個(gè)EmailAttachment對(duì)象,并調(diào)用MultiPartEmail.attach();就可以發(fā)送多個(gè)附件.

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

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

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

    評(píng)論

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

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

    # 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("這是一個(gè)測(cè)試","text/plain;charset=GBK");  回復(fù)  更多評(píng)論
      

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

    主站蜘蛛池模板: 国产成人免费a在线视频色戒| 亚洲AV无码成人精品区在线观看 | 91免费国产自产地址入| 亚洲成网777777国产精品| 中文亚洲AV片不卡在线观看 | 亚洲久热无码av中文字幕| 九九精品免费视频| 中文字幕乱码亚洲无线三区 | 无码日韩人妻AV一区免费l| 又粗又黄又猛又爽大片免费| 国产成人亚洲毛片| 亚洲午夜AV无码专区在线播放| 日韩亚洲AV无码一区二区不卡| 色欲A∨无码蜜臀AV免费播| 久久精品国产亚洲av水果派| 18观看免费永久视频| 亚洲国产区男人本色在线观看| 在线免费一区二区| 一级毛片免费观看不收费| 亚洲成a人片在线观看无码专区| 三年片在线观看免费大全电影| 亚洲人成777在线播放| 国产精品免费看香蕉| 精品人妻系列无码人妻免费视频| 亚洲国产精品福利片在线观看 | 在线观看av永久免费| 精品亚洲一区二区| 114级毛片免费观看| 亚洲欧洲av综合色无码| 亚洲欧洲日产国码高潮αv| 亚洲粉嫩美白在线| 免费又黄又硬又爽大片| 久章草在线精品视频免费观看| 免费日韩在线视频| 亚洲国产欧洲综合997久久| 4444www免费看| 成a人片亚洲日本久久| 免费看美女让人桶尿口| 亚洲一卡2卡4卡5卡6卡在线99| 四虎影视成人永久免费观看视频 | 欧亚一级毛片免费看|