send data to email in background

ε祈祈猫儿з 提交于 2019-11-29 11:23:26

I create open source library for this. Usage is very simple:

BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("yourgmail@gmail.com");
bm.setGmailPassword("yourgmailpassword");
bm.setMailTo("receiver@gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();

With this permissions

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/> 

You can download it here: https://github.com/kristijandraca/BackgroundMailLibrary

In android, You can send Email with explicit email intent however it will show a email screen and will not allow to send data in background.

To send data in background, you can use java mail api to send the mail.

Take a look on this http://www.tutorialspoint.com/java/java_sending_email.htm

This is one way of sending emails by using explicit email intent but this will not send in background

 Intent sendemai = new Intent(Intent.ACTION_SEND);
 sendemai.putExtra(Intent.EXTRA_EMAIL,
                        new String[] { toaddress });
 sendemai.putExtra(Intent.EXTRA_CC,
                        new String[] { emailadd }); 
 sendemai.putExtra(Intent.EXTRA_SUBJECT, sub);
 sendemai.putExtra(Intent.EXTRA_TEXT, body); 
 // need this to prompts email client only
 sendemai.setType("message/rfc822"); 
 startActivity(Intent.createChooser(payment_request,
                        "Select email application"));

If you want to send in background then you need to provide some of user secure credentials.See Here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!