<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无码不卡免费 | 国产成人午夜精品免费视频| 亚洲精品高清视频| 日本免费在线观看| 91亚洲国产成人精品下载| 99蜜桃在线观看免费视频网站| 精品亚洲永久免费精品| 国产精品免费一区二区三区四区| 久久99国产亚洲精品观看| 亚洲免费电影网站| 久久久国产亚洲精品| 免费看国产精品麻豆| 国产免费内射又粗又爽密桃视频| 国产亚洲日韩在线三区| 久久精品成人免费看| 亚洲成A∨人片在线观看无码| 国产免费av片在线看| 久久久久久久久无码精品亚洲日韩| 免费jjzz在在线播放国产| 99久久婷婷免费国产综合精品| 亚洲高清在线观看| 久久电影网午夜鲁丝片免费| 亚洲AV无码片一区二区三区| 亚洲精品无码永久在线观看| 久久久久免费精品国产小说| 亚洲性色高清完整版在线观看| 国产片免费在线观看| a在线观看免费视频| wwwxxx亚洲| 亚洲中文字幕无码中文字在线| 18禁美女裸体免费网站| 在线观看亚洲专区| 亚洲人成网址在线观看| 国产又黄又爽又猛的免费视频播放| 成人黄网站片免费视频| 亚洲人成网站999久久久综合| 亚洲啪啪综合AV一区| 女人18毛片水真多免费看| a级成人毛片免费视频高清|