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已寫過, 就不發布到首頁了

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

          主站蜘蛛池模板: 司法| 阳泉市| 邵武市| 象州县| 安福县| 霍城县| 常山县| 惠来县| 玛纳斯县| 库尔勒市| 延安市| 瑞丽市| 晋州市| 屯门区| 乌鲁木齐县| 平原县| 永修县| 偏关县| 禄丰县| 瓮安县| 浙江省| 锡林郭勒盟| 高清| 北流市| 星子县| 化隆| 孟津县| 浪卡子县| 汝州市| 哈巴河县| 昭通市| 融水| 孟津县| 黑水县| 屏东市| 拜城县| 沂南县| 桂林市| 恩施市| 乐昌市| 安陆市|