send data to email in background

元气小坏坏 提交于 2019-12-18 06:49:35

问题


I am working on sending my message data on my email Id.I have made a mainActivity class containing an editText (for emailId) and a Button. Another class is BroadcastReceiver class in which I retrieve data. Now I can't understand how to send that data to the provided email in Background. I have googled a lot but can't get the required response. Please share the ideas and help me in it.


回答1:


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




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/19974342/send-data-to-email-in-background

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