首页 android邮件发送几种方式

android邮件发送几种方式

举报
开通vip

android邮件发送几种方式android邮件发送几种方式 博客分类: · android    android中发送邮件我大概发现了3种,代码如下 Java代码   1. package src.icetest;   2.    3. import org.apache.commons.mail.EmailException;   4. import org.apache.commons.mail.HtmlEmail;   5.    6. import android.app.Activity;   7. i...

android邮件发送几种方式
android邮件发送几种方式 博客分类: · android    android中发送邮件我大概发现了3种,代码如下 Java代码   1. package src.icetest;   2.    3. import org.apache.commons.mail.EmailException;   4. import org.apache.commons.mail.HtmlEmail;   5.    6. import android.app.Activity;   7. import android.content.Intent;   8. import android.os.Bundle;   9. import android.util.Log;   10.    11. public class IcetestActivity extends Activity {   12.     /** Called when the activity is first created. */   13.     @Override   14.     public void onCreate(Bundle savedInstanceState) {   15.         super.onCreate(savedInstanceState);   16.         setContentView(R.layout.main);   17.         Log.i("IcetestActivity", "start ice test step 1");   18.         // sendMailIntent();   19.         //sendMailByApache();   20.         sendMailByJavaMail();   21.     }   22.    23.     // you need config the mail app in your android moble first,and the mail will send by the mail app. and there are one big bug:   24.     //you can't send the mail Silently and you need to click the send button   25.     public int sendMailByIntent() {   26.         String[] reciver = new String[] { "181712000@qq.com" };   27.         String[] mySbuject = new String[] { "test" };   28.         String myCc = "cc";   29.         String mybody = "测试Email Intent";   30.         Intent myIntent = new Intent(android.content.Intent.ACTION_SEND);   31.         myIntent.setType("plain/text");   32.         myIntent.putExtra(android.content.Intent.EXTRA_EMAIL, reciver);   33.         myIntent.putExtra(android.content.Intent.EXTRA_CC, myCc);   34.         myIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mySbuject);   35.         myIntent.putExtra(android.content.Intent.EXTRA_TEXT, mybody);   36.         startActivity(Intent.createChooser(myIntent, "mail test"));   37.    38.         return 1;   39.    40.     }   41.    /*this method can't be used in android mobile successful,but it can run normally in PC.  42.     Because it will cause the java.lang.NoClassDefFoundError: javax.activation.DataHandler error  43.     May be there are some way to solove it ......there are always javax package not found in android virtual mobile.  44.     By the way ,the method use Apache mail jar        45.     */   46.     public int sendMailByApache() {   47.    48.         try {   49.             HtmlEmail email = new HtmlEmail();   50.             // 这里是发送服务器的名字   51.             email.setHostName("smtp.gmail.com");   52.             // 编码集的设置   53.             email.setTLS(true);   54.             email.setSSL(true);   55.    56.             email.setCharset("gbk");   57.             // 收件人的邮箱   58.             email.addTo("181712000@qq.com");   59.             // 发送人的邮箱   60.             email.setFrom("wcf0000@gmail.com");   61.             // 如果需要认证信息的话,设置认证:用户名-密码。分别为发件人在邮件服务器上的注册名称和密码   62.             email.setAuthentication("wcf1000", "00000");   63.             email.setSubject("测试Email Apache");   64.             // 要发送的信息   65.             email.setMsg("测试Email Apache");   66.             // 发送   67.             email.send();   68.         } catch (EmailException e) {   69.             // TODO Auto-generated catch block   70.             Log.i("IcetestActivity", e.getMessage());   71.         }   72.    73.         return 1;   74.     }   75. /*  76.  * this method use javamail for android ,it is a good jar,  77.  * you can see the demo in http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android  78.  * and you also need three jars ,which I offered in attachement  79.  *   80.  * */   81.     public int sendMailByJavaMail() {   82.         Mail m = new Mail("wcfXXXX@gmail.com", "XXXXX");   83.         m.set_debuggable(true);   84.         String[] toArr = {"18170000@qq.com"};    85.         m.set_to(toArr);   86.         m.set_from("18170000@qq.com");   87.         m.set_subject("This is an email sent using icetest from an Android device");   88.         m.setBody("Email body. test by Java Mail");   89.         try {   90.             //m.addAttachment("/sdcard/filelocation");    91.             if(m.send()) {    92.             Log.i("IcetestActivity","Email was sent successfully.");   93.                            94.             } else {   95.                 Log.i("IcetestActivity","Email was sent failed.");   96.             }   97.         } catch (Exception e) {   98.             // Toast.makeText(MailApp.this,   99.             // "There was a problem sending the email.",   100.             // Toast.LENGTH_LONG).show();   101.             Log.e("MailApp", "Could not send email", e);   102.         }   103.    104.         return 1;   105.     }   106. }     第一种 方法 快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载 是调用了系统的mail app,你首先要配置系统的mail app,但是这个方法的最大问 快递公司问题件快递公司问题件货款处理关于圆的周长面积重点题型关于解方程组的题及答案关于南海问题 是,你运行这个方法后 他并不会默认的发送邮件,而是弹出mail的app界面,你需要手动的点击发送,如图     第二种,是调用了apache的common库,在pc上可以正常运行,但是在android虚拟机中会报错java.lang.NoClassDefFoundError: javax.activation.DataHandler error javax包无法找到,我看了下这个问题还是比较普遍的,大家普遍 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 示虚拟机是被阉割的版本,javax好像存在不全,这个实际上就无法运行   第三种,实际是javamail有人做了移植,专门为android做了开发,这下就比较好了,网上的demo代码也比较到位,只有一个问题,就是要自己添加一个mail.java,而且对stmp要手动添加。   其实理论上还应该有一种,自己实现smtp服务器,全程采用socket编程,直接与目标服务器交流,这个win下面我写过,但是android下就算了,而且长期来讲面临着smtp服务器以后会被进行方向查询,以提高安全性。
本文档为【android邮件发送几种方式】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_925133
暂无简介~
格式:doc
大小:93KB
软件:Word
页数:6
分类:互联网
上传时间:2013-03-31
浏览量:19