How to send emails from my Android application?
The best (and easiest) way is to use an Intent
:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
Otherwise you'll have to write your own client.
how send email from android application directly?
There are two ways to send email from android application directly without any intent
- using SMTP & JavaMail API follow the link for details
- using Webservice( for example PHP script ) so there is a server side code and you hit that URL with param like ( name,subject etc) so basically PHP code send mail at the end and it's very easy to use .
Personally, I suggest you use Webservice because it's simpler than first approach.
** Edit: You can save email in sharedpreferences
or database and fetch it from there when you try to send mail rather than hardcoding it to avoid theft email risk.(directly putting mail address inside code)
Anyway you can prevent other from getting your full source code
.See this answer
Send data from Android app with email
GmailBackground is small library to send an email in background without user interaction :
Usage:
BackgroundMail.newBuilder(this)
.withUsername("username@gmail.com")
.withPassword("password12345")
.withMailto("toemail@gmail.com")
.withType(BackgroundMail.TYPE_PLAIN)
.withSubject("this is the subject")
.withBody("this is the body")
.withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
@Override
public void onSuccess() {
//do some magic
}
})
.withOnFailCallback(new BackgroundMail.OnFailCallback() {
@Override
public void onFail() {
//do some magic
}
})
.send();
Source
(I've tested it myself)
How to send emails from my app using a Gmail account?
For anyone interested, no solution worked. Gmail just refused to allow different locations to login, because of extra-security (without option to disable this).
I moved to use other email provider. No problems anymore with the same code.
Related Topics
How to Change the Status Bar Color in Android
How to Execute Dex: Method Id Not in [0, 0Xffff]: 65536
Changing Locale Within the App Itself
How to Get Zoom Functionality For Images
Ioexception: Read Failed, Socket Might Closed - Bluetooth on Android 4.3
How to Put Google Maps V2 on a Fragment Using Viewpager
Android Respond to Url in Intent
How to Get Complete Address from Latitude and Longitude
How to Change Current Theme At Runtime in Android
Retrieve a Fragment from a Viewpager
Open Another Application from Your Own (Intent)
Key Hash For Android-Facebook App
Android Action_Image_Capture Intent
How to Use Recyclerview Inside Nestedscrollview
Recyclerview Inside Scrollview Is Not Working
How to Detect When Wifi Connection Has Been Established in Android