android 发邮件-JavaMail-Android

凌修伟
2023-12-01

JavaMail-Android Project:
http://code.google.com/p/javamail-android/
Jar包使用方式:
在Android项目中直接导入即可

 

主要代码:

 button.setOnClickListener(new OnClickListener(){  
           @Override 
           public void onClick(View view) {  
               try {  
                   MailAccount account = new MailAccount(  
                           "account@mail.com", //邮箱帐号  
                           "password", //邮箱密码  
                           "465", //端口,采用SSL加密的SMTP协议默认端口为465  
                           "465",  
                           "smtp.qq.com" //smtp服务器  
                           );;  
                   MailItem item = new MailItem(  
                           "from@mail.com", //发件人  
                           new String[]{"to@mail.com"}, //收件人,可以有多个   
                           "subject", //邮件主题  
                           "body" //邮件内容  
                           );  
                   item.addAttachment("/sdcard/test.jpg"); //附件  
                     
                   Mail mail = new Mail();  
                   mail.send(account, item);  
               } catch (Exception e) {  
                   e.printStackTrace();  
               }  
           }  
       });  



 

 类似资料: