waterye

          use jakarta-commons email

          requires jar: commons-email-1.0.jar, mail.jar, activation.jar

          1. send text mail
          SimpleEmail email = new SimpleEmail();
          email.setHostName(
          "211.154.104.29");
          email.setAuthentication(
          "water@itorgan.com", password);
          email.addTo(
          "waterye@gmail.com""Water Ye");
          email.setFrom(
          "water@itorgan.com""Water Ye");
          email.setSubject(
          "Test message");
          email.setMsg(
          "This is a simple test of commons-email");
          email.send();
          中文問題:
          // email.setMsg("測試郵件");
          email.setCharset("UTF-8");
          email.setContent(
          "測試郵件""text/plain;charset=GBK");
          SimpleEmail封得太過簡單, 看代碼就知道了.

          2. Sending email with attachments
          // Create the attachment
          EmailAttachment attachment = new EmailAttachment();
          attachment.setPath(
          "C:/mail/hello.groovy");
          attachment.setDisposition(EmailAttachment.ATTACHMENT);
          attachment.setDescription(
          "hello.groovy");
          attachment.setName(
          "hello.groovy");

          // Create the email message
          MultiPartEmail email = new MultiPartEmail();
          email.setHostName(
          "211.154.104.29");
          email.setAuthentication(
          "water@itorgan.com", password);
          email.addTo(
          "waterye@gmail.com""Water Ye");
          email.setFrom(
          "water@itorgan.com""Water Ye");
          email.setSubject(
          "hello groovy");
          email.setMsg(
          "groovy hello world");

          email.attach(attachment);   
          // add the attachment
          email.send();   // send the email

          3. send html email
          // Create the email message
          HtmlEmail email = new HtmlEmail();
          email.setHostName(
          "211.154.104.29");
          email.setAuthentication(
          "water@itorgan.com", password);
          email.addTo(
          "waterye@gmail.com""Water Ye");
          email.setFrom(
          "water@itorgan.com""Water Ye");
          email.setSubject(
          "Test email with inline image");

          // embed the image and get the content id
          URL url = new URL("http://www.itorgan.com/images/index/top1.gif");
          String cid 
          = email.embed(url, "Itorgan logo");

          email.setHtmlMsg(
          "<html>The itorgan logo - <img src=\"cid:" + cid + "\"></html>"); // set the html message

          email.setTextMsg(
          "Your email client does not support HTML messages"); // set the alternative message

          email.send();


          martin xus已寫過, 就不發(fā)布到首頁了

          posted on 2005-09-30 16:42 waterye 閱讀(576) 評論(0)  編輯  收藏 所屬分類: Java

          主站蜘蛛池模板: 勃利县| 阿拉善盟| 康平县| 曲麻莱县| 当阳市| 泉州市| 美姑县| 桦川县| 攀枝花市| 溧水县| 金昌市| 贵南县| 灵寿县| 三都| 凉山| 盐池县| 丁青县| 潼南县| 寻乌县| 双鸭山市| 凤城市| 盐城市| 晋城| 宾川县| 石楼县| 陵水| 吉水县| 文水县| 浏阳市| 五寨县| 湖南省| 德钦县| 绥滨县| 蓬溪县| 白银市| 介休市| 瑞昌市| 延川县| 静海县| 宁蒗| 通州区|