heting

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            40 隨筆 :: 9 文章 :: 45 評(píng)論 :: 0 Trackbacks

          import org.apache.commons.mail.*;  
           
          public class test {  
               
          //程序主方法  
          public static void main(String[] args)throws Exception {  
             test as
          =new test();  
               String host 
          = "smtp.sina.com";  
                   String from 
          = "javalihan@sina.com";  
                   String username 
          = "javalihan";  
                   String password 
          = "javame";  
                   
          //接收者郵箱  
                   String to = "lbl2006@qq.com";  
                   String subject
          ="這是測(cè)試主題!";  
                   String mailConent
          ="這是測(cè)試郵件";  
                    
          //調(diào)用發(fā)送附件郵件方法  
             as.sendAttachmentMail(host, from, username, password, to, subject, mailConent);  
          }
            

             
          public boolean sendAttachmentMail(String host,String from,String username,  
              String password,String to,String subject,String mailConent)
          throws Exception{  
                 
          //創(chuàng)建附件對(duì)象  
              EmailAttachment attachment = new EmailAttachment();  
                          
          /*附件的地址*/       
              attachment.setPath(
          "E:\\commons-email-1.0.rar");    
                                
          //設(shè)定為附件  
                    attachment.setDisposition(EmailAttachment.ATTACHMENT);  
                    
          /*附件的描述*/  
                    attachment.setDescription(
          "jPortMap項(xiàng)目設(shè)計(jì)附件文檔");  
                    
          /*附件的名稱,必須和文件名一致*/  
                    attachment.setName(
          "Eclipse中文教程.pdf");  
                    
          /*new一個(gè)HtmlEmail發(fā)送對(duì)象*/  
              HtmlEmail email 
          = new HtmlEmail();    
                 email.setAuthentication(username, password);  
              email.setHostName(host);  
              email.addTo(to, from);  
              email.setFrom(from);  
              email.setSubject(subject);  
                    
          //注意,發(fā)送內(nèi)容時(shí),后面這段會(huì)讓中文正常顯示,否則亂碼  
              email.setCharset("GB2312");  
              email.setHtmlMsg(
          "<html>這是封測(cè)試附件郵件</html>"); /*郵件內(nèi)容*/  
                    
          //添加附件對(duì)象  
              email.attach(attachment);  
              
          //發(fā)送  
              email.send();  
              System.out.println(
          "帶符件的郵件發(fā)送成功!");  
              
          return true;  

          }
            
          }
           
          posted on 2008-12-20 08:48 賀挺 閱讀(140) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 西贡区| 巴彦淖尔市| 石渠县| 松原市| 乌拉特后旗| 连南| 东台市| 黄龙县| 隆林| 浑源县| 邵武市| 海南省| 拜城县| 兴安盟| 马尔康县| 贞丰县| 恩平市| 武汉市| 邹城市| 洞口县| 阜新市| 瓮安县| 泰宁县| 平泉县| 格尔木市| 平远县| 根河市| 大方县| 杭锦后旗| 子洲县| 盘锦市| 潮安县| 昔阳县| 昌乐县| 大悟县| 云南省| 乌鲁木齐市| 兴山县| 瑞丽市| 马关县| 永寿县|