今天折腾Android应用中发email,遇到的问题不少啊!累的半死,写个总结,洗洗睡!
Android应用中发邮件一般有这几种方式:
(1)通过intent Email客户端来发,虽然简单,但会弹出邮箱窗口,在应用中不友好;
(2)通过调用第三方的Java mail库来发,参考这两篇:
http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_(no_Intents)_in_Android
(3)第一第二中方法的结合,需要在客户端安装第三方应用。这样可以避免弹出发邮件对话框,但需要配置这个客户端也不方便。参考:http://tools.jackersoft.com/jmail/api.html
(4)通过网络服务器来发,Android中将需要发送的内容(比如通过JSON)POST出去。服务器端收到后执行发邮件操作。服务器可选的就很多了,比如PHP、JBOSS、GWT、PYTHON。
PHP可参考:
http://edwin.baculsoft.com/2011/12/how-to-handle-json-post-request-using-php/
Ubuntu安装sendmail可参考:
http://sunnycoolboy.blog.sohu.com/182319658.html
Python可参考:(Python + CGI)