heting

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            40 隨筆 :: 9 文章 :: 45 評論 :: 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
          ="這是測試主題!";  
                   String mailConent
          ="這是測試郵件";  
                    
          //調用發送附件郵件方法  
             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{  
                 
          //創建附件對象  
              EmailAttachment attachment = new EmailAttachment();  
                          
          /*附件的地址*/       
              attachment.setPath(
          "E:\\commons-email-1.0.rar");    
                                
          //設定為附件  
                    attachment.setDisposition(EmailAttachment.ATTACHMENT);  
                    
          /*附件的描述*/  
                    attachment.setDescription(
          "jPortMap項目設計附件文檔");  
                    
          /*附件的名稱,必須和文件名一致*/  
                    attachment.setName(
          "Eclipse中文教程.pdf");  
                    
          /*new一個HtmlEmail發送對象*/  
              HtmlEmail email 
          = new HtmlEmail();    
                 email.setAuthentication(username, password);  
              email.setHostName(host);  
              email.addTo(to, from);  
              email.setFrom(from);  
              email.setSubject(subject);  
                    
          //注意,發送內容時,后面這段會讓中文正常顯示,否則亂碼  
              email.setCharset("GB2312");  
              email.setHtmlMsg(
          "<html>這是封測試附件郵件</html>"); /*郵件內容*/  
                    
          //添加附件對象  
              email.attach(attachment);  
              
          //發送  
              email.send();  
              System.out.println(
          "帶符件的郵件發送成功!");  
              
          return true;  

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

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 浮山县| 济源市| 临沭县| 秦皇岛市| 石城县| 中超| 沾益县| 古交市| 定远县| 安远县| 上高县| 高淳县| 关岭| 宾川县| 大冶市| 高碑店市| 剑川县| 定西市| 靖安县| 什邡市| 沙湾县| 贡嘎县| 巴彦淖尔市| 本溪市| 鲁甸县| 宕昌县| 彭阳县| 安达市| 东明县| 永仁县| 安平县| 曲沃县| 北宁市| 建平县| 张北县| 封开县| 德庆县| 延庆县| 饶阳县| 越西县| 阿合奇县|