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

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

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

    blogjava's web log

    blogjava's web log
    ...

    spring郵件發(fā)送例

    appcontextcos.xml配置文件

    ?

    <!DOCTYPE?beans?PUBLIC?"-//SPRING//DTD?BEAN//EN"?"http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    ?
    <bean?id="sender"?class="org.springframework.mail.javamail.JavaMailSenderImpl">
    ??
    <property?name="host">
    ???
    <value>smtp.163.com</value>
    ??
    </property>
    ??
    <property?name="username">
    ???
    <value>wujun1866</value>
    ??
    </property>
    ??
    <property?name="password">
    ???
    <value>郵箱密碼</value>
    ??
    </property>
    ????????
    <property?name="javaMailProperties">
    ????????
    <props>
    ????????
    <prop?key="mail.smtp.auth">true</prop>
    ????????
    </props>
    ????????
    </property>

    ????
    </bean>

    ?
    <bean?id="TestSendMessage"?class="com.wjj.testMail">
    ??
    <property?name="javaMailSender">
    ???
    <ref?bean="sender"/>
    ??
    </property>
    ??
    <property?name="to">
    ???
    <value>renxianqi.2008@163.com</value>
    ??
    </property>
    ??
    <property?name="from">
    ???
    <value>wujun1866@163.com</value>
    ??
    </property>
    ??
    <property?name="subject">
    ???
    <value>test</value>
    ??
    </property>
    ?
    </bean>
    </beans>

    測試代碼..

    public?static?void?main(String[]?args)?{
    ????????ApplicationContext?ac?
    =?new?ClassPathXmlApplicationContext(
    ????????????????
    "appcontext.xml");
    ????????JavaMailSender?mailSend?
    =?(JavaMailSender)?ac.getBean("TestSendMessage");
    ????????MimeMessagePreparator?mail?
    =?new?MimeMessagePreparator()?{
    ????????????????
    public?void?prepare(MimeMessage?message)
    ????????????????????
    throws?MessagingException?{
    ?????????????????????
    //收件人
    ????????????????????message.setRecipient(Message.RecipientType.TO,
    ????????????????????????
    new?InternetAddress("renxianqi.2008#163.com"));
    ????????????????????
    //發(fā)件人
    ????????????????????message.setFrom(new?InternetAddress(
    ????????????????????????????
    "wujun1866#163.com"));
    ????????????????????
    //內(nèi)容
    ????????????????????message.setText("this?is?a?test?!");
    ????????????????????message.setSubject(
    "title標(biāo)題");
    ????????????????????
    //添加附件
    ????????????????????Multipart?multipart?=?new?MimeMultipart();

    ????????????????????BodyPart?attachmentPart
    =?new?MimeBodyPart();
    ????????????????????DataSource?source?
    =?new?FileDataSource("C:\\1.bmp");
    ????????????????????attachmentPart.setDataHandler(
    new?DataHandler(source));
    ????????????????????attachmentPart.setFileName(
    "1.bmp");
    ????????????????????
    //attachmentPart.setText("tedddddd");
    ??????????????????
    //??sun.misc.BASE64Encoder?enc?=?new?sun.misc.BASE64Encoder();
    ??????????????????
    //??messageBodyPart.setFileName("=?GBK?B?"+enc.encode(attachmentName.getBytes())+"?=");
    ??????????????????multipart.addBodyPart(attachmentPart);
    ??????????????????message.setContent(multipart);

    ????????????????}

    ????????????}
    ;

    ????????
    try?{
    ????????????mailSend.send(mail);
    ????????????System.out.print(
    "k");
    ????????}
    ?catch?(MailException?ex)?{
    ????????????log.error(
    "error:",?ex);
    ????????}

    ????}

    }



    相關(guān)java發(fā)送郵件有用的資源

    使用JavaMail收發(fā)郵件,解決了中文附件名問題

    JavaMail 深入淺出

    ?

    posted on 2006-06-22 17:37 record java and net 閱讀(1584) 評(píng)論(0)  編輯  收藏 所屬分類: Spring

    導(dǎo)航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動(dòng)態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評(píng)論

    主站蜘蛛池模板: 亚洲av成人一区二区三区观看在线| 国产成人高清亚洲一区久久 | 最新亚洲人成无码网站| 波多野结衣中文一区二区免费| 一区视频免费观看| 日本久久久久亚洲中字幕| 在线成人a毛片免费播放| 中文字幕成人免费高清在线视频| 亚洲欧洲日本精品| 亚洲麻豆精品国偷自产在线91| 毛片无码免费无码播放| 人人狠狠综合久久亚洲| 亚洲精品视频在线| 又大又黄又粗又爽的免费视频| 无码人妻丰满熟妇区免费| 亚洲AV成人无码久久WWW| 亚洲国产美国国产综合一区二区| 免费看片免费播放| 国产一区二区免费| 亚洲a∨无码精品色午夜| 久久综合图区亚洲综合图区| 国产小视频在线观看免费| 95免费观看体验区视频| 午夜免费国产体验区免费的| 亚洲中文无码av永久| 亚洲老妈激情一区二区三区| 国产精品国产午夜免费福利看| 18禁止看的免费污网站| 好男人资源在线WWW免费| 亚洲精品无码aⅴ中文字幕蜜桃| 亚洲AV美女一区二区三区| 亚洲国产成人a精品不卡在线| 亚欧人成精品免费观看| 中文字幕无码毛片免费看| 国产亚洲精品AAAA片APP| 亚洲国产精品人久久电影| 亚洲成在人线av| 精品国产亚洲男女在线线电影 | 久久久久亚洲精品影视| 亚洲人妻av伦理| 日本免费网站在线观看|