I am trying to create a mail sending application in Android.
If I use:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
This will launch the built-in Android application; I'm trying to send the mail on button click directly without using this application.
I am unable to run Vinayak B's code. Finally i solved this issue by following :
1.Using this
2.Applying AsyncTask.
3.Changing security issue of sender gmail account.(Change to "TURN ON") in this
100% working code with demo You can also send multiple email using this answer.
Download Project HERE
Step 1 : Download mail,activation,additionnal jar files and add in your project libs folder in android studio. I added a screen shot see below Download link
Login with gmail (using your from mail) and TURN ON toggle button LINK
Most of the people forget about this step i hope you will not.
Step 2 : After completing this process. Copy and past this classes into your project.
GMail.java
SendMailTask.java
Step 3 : Now you can change this class according to your needs also you can send multiple mail using this class. i provide xml and java file both.
activity_mail.xml
SendMailActivity.java
Note Dont forget to add internet permission in your AndroidManifest.xml file
<uses-permission android:name="android.permission.INTERNET"/>
Hope it work if it not then just comment down below.
To add attachment, don't forget to add.
Send e-mail in Android using the JavaMail API using Gmail authentication.
Steps to create a sample Project:
MailSenderActivity.java:
GMailSender.java:
JSSEProvider.java:
ADD 3 jars found in the following link to your Android Project
Click here - How to add External Jars
And don't forget to add this line in your manifest:
Just click below link to change account access for less secure apps https://www.google.com/settings/security/lesssecureapps
Run the project and check your recipient mail account for the mail. Cheers!
P.S. And don't forget that you cannot do network operation from any Activity in android. Hence it is recommended to use
AsyncTask
orIntentService
to avoid network on main thread exception.Jar files: https://code.google.com/archive/p/javamail-android/
Edit: JavaMail 1.5.5 claims to support Android, so you shouldn't need anything else.
I've ported the latest JavaMail (1.5.4) to Android. It's available in Maven Central, just add the following tobuild.gradle
~~You can then follow the official tutorial.
Source code is available here: https://bitbucket.org/artbristol/javamail-forked-android
Did you consider using Apache Commons Net ? Since 3.3, just one jar (and you can depend on it using gradle or maven) and you're done : http://blog.dahanne.net/2013/06/17/sending-a-mail-in-java-and-android-with-apache-commons-net/