隨筆 - 23  文章 - 11  trackbacks - 0
          <2007年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          package org.wzywjy.mail;

          import java.util.Date;
          import java.util.Properties;
          import javax.mail.Message;
          import javax.mail.MessagingException;
          import javax.mail.Session;
          import javax.mail.Transport;
          import javax.mail.internet.AddressException;
          import javax.mail.internet.InternetAddress;
          import javax.mail.internet.MimeMessage;

          public class TestMail {

          public final static String SMTPSERVER = "smtp.163.com";
          public final static String POPSERVER = "pop.163.com";
          public final static String ACCOUNT = "test";
          public final static String PWD = "test";
          public final static String MAILADDR = "test@163.com";

          public void sendMail(String to, String from, String subject, String body) throws AddressException, MessagingException {
          Properties pro = System.getProperties();
          pro.put("mail.smtp.host", SMTPSERVER);
          pro.put("mail.smtp.auth", "true");
          Session session = Session.getDefaultInstance(pro, null);

          Message msg = new MimeMessage(session);
          msg.setFrom(new InternetAddress(from));
          msg.setRecipient(Message.RecipientType.TO, InternetAddress.parse(to, false)[0]);
          msg.setSubject(subject);
          msg.setText(body);
          msg.setHeader("X-Mailer", "LOTONtechEmail");
          msg.setSentDate(new Date());

          Transport transport = session.getTransport("smtp");
          System.out.println("connecting...");
          transport.connect(SMTPSERVER, ACCOUNT, PWD);
          System.out.println("Sending message");
          transport.sendMessage(msg, msg.getAllRecipients());
          transport.close();
          }

          public static void main(String[] args) {
          TestMail test = new TestMail();
          try {
          test.sendMail(MAILADDR, MAILADDR, "test", "我的一個測試");
          } catch (AddressException e) {
          e.printStackTrace();
          } catch (MessagingException e) {
          e.printStackTrace();
          }
          }
          }

          posted on 2006-09-15 10:30 小小~咖啡豆 閱讀(301) 評論(1)  編輯  收藏 所屬分類: 其他

          FeedBack:
          # re: 一個簡單的發送郵件的例子[未登錄] 2007-10-19 11:40 yuan
          強!!!!!!!!!!  回復  更多評論
            
          主站蜘蛛池模板: 泾阳县| 北京市| 海兴县| 郓城县| 特克斯县| 乡宁县| 合作市| 镇雄县| 巨野县| 瓦房店市| 咸宁市| 上虞市| 盘锦市| 河东区| 通山县| 天峨县| 淮安市| 莒南县| 陆河县| 临高县| 封开县| 黄冈市| 三门县| 北宁市| 万荣县| 达拉特旗| 丰原市| 黄骅市| 文昌市| 海宁市| 康马县| 攀枝花市| 新巴尔虎右旗| 进贤县| 清原| 江西省| 资中县| 渭南市| 中超| 鸡东县| 社旗县|