In this post we will create an Android Email App.
We will not use the default Android Email Client to send emails instead we will use Javamail API to create our own email sender. And you can also use this App for Email.
So if you are searching Best Email App for Android then try the app created by yourself 😉
Before going through the tutorial you can check the following video to see exactly what you will be creating in this tutorial.
Android Email App – Video
Download Javamail API for Android
- For this Android Email App we will use Javamail API, so before starting our android project download Javamail API from link given below
[download id=”1481″]
- You will get a zip file from the above link. Extract the zip and you will get three .jar files. We will use these .jar files in our android email app project.
Creating Android Email App in Android Studio
- Open Android Studio and create a new android project.
- First we will add the downloaded .jar’s to our project.
- From the left panel click on Android -> Project (see the image below)

- Now you will get the libs folder inside projectfolder -> app -> libs . Paste all the three .jar files which you have downloaded above inside the libs folder. (See the image below)

- Now go to file -> project structure.

- Now go to dependencies and from the right click on the green + sign and then click on file dependencies.

- Now go to libs folder and add all the three .jar files (you can see in the image)

- Now click on ok, ok and you have added the apis to your project.
- Now come to activity_main.xml and create the following layout.

- Use the following code for creating the above layout.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:text="Recipient Email" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editTextEmail" /> <TextView android:text="Subject" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editTextSubject" /> <TextView android:text="Message" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:lines="4" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editTextMessage" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/buttonSend" android:text="Send"/> </LinearLayout> |
- For this android email app we will use gmail to send emails. So create a new java class named Config.java and write the following code.
1 2 3 4 5 6 7 8 9 10 11 | package net.simplifiedcoding.javamailexample; /** * Created by Belal on 10/30/2015. */ public class Config { public static final String EMAIL ="your-gmail-username"; public static final String PASSWORD ="your-gmail-password"; } |
- You have to write your gmail username and password.
- Now create a new class SendMail.java. It will send our email. Write the following code in this class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | package net.simplifiedcoding.javamailexample; import android.app.ProgressDialog; import android.content.Context; import android.os.AsyncTask; import android.widget.Toast; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /** * Created by Belal on 10/30/2015. */ //Class is extending AsyncTask because this class is going to perform a networking operation public class SendMail extends AsyncTask<Void,Void,Void> { //Declaring Variables private Context context; private Session session; //Information to send email private String email; private String subject; private String message; //Progressdialog to show while sending email private ProgressDialog progressDialog; //Class Constructor public SendMail(Context context, String email, String subject, String message){ //Initializing variables this.context = context; this.email = email; this.subject = subject; this.message = message; } @Override protected void onPreExecute() { super.onPreExecute(); //Showing progress dialog while sending email progressDialog = ProgressDialog.show(context,"Sending message","Please wait...",false,false); } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); //Dismissing the progress dialog progressDialog.dismiss(); //Showing a success message Toast.makeText(context,"Message Sent",Toast.LENGTH_LONG).show(); } @Override protected Void doInBackground(Void... params) { //Creating properties Properties props = new Properties(); //Configuring properties for gmail //If you are not using gmail you may need to change the values props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); //Creating a new session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { //Authenticating the password protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(Config.EMAIL, Config.PASSWORD); } }); try { //Creating MimeMessage object MimeMessage mm = new MimeMessage(session); //Setting sender address mm.setFrom(new InternetAddress(Config.EMAIL)); //Adding receiver mm.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); //Adding subject mm.setSubject(subject); //Adding message mm.setText(message); //Sending email Transport.send(mm); } catch (MessagingException e) { e.printStackTrace(); } return null; } } |
- Now come to MainActivity.java and write the following code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | package net.simplifiedcoding.javamailexample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import java.util.Properties; import javax.mail.PasswordAuthentication; import javax.mail.Session; public class MainActivity extends AppCompatActivity implements View.OnClickListener { //Declaring EditText private EditText editTextEmail; private EditText editTextSubject; private EditText editTextMessage; //Send button private Button buttonSend; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Initializing the views editTextEmail = (EditText) findViewById(R.id.editTextEmail); editTextSubject = (EditText) findViewById(R.id.editTextSubject); editTextMessage = (EditText) findViewById(R.id.editTextMessage); buttonSend = (Button) findViewById(R.id.buttonSend); //Adding click listener buttonSend.setOnClickListener(this); } private void sendEmail() { //Getting content for email String email = editTextEmail.getText().toString().trim(); String subject = editTextSubject.getText().toString().trim(); String message = editTextMessage.getText().toString().trim(); //Creating SendMail object SendMail sm = new SendMail(this, email, subject, message); //Executing sendmail to send email sm.execute(); } @Override public void onClick(View v) { sendEmail(); } } |
- Finally add internet permission to manifest.
1 2 3 | <uses-permission android:name="android.permission.INTERNET"/> |
- Thats it now run your application.

- Bingo! It is working absolutely fine. You can also download the source code of my project from below.
Get source code of Android Email App
So thats all for this Android Email App tutorial. Leave your comments if you are having any queries or trouble for this Android Email App. Thank You 🙂

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
Hii thanks for the tutorial its working fine with Gmail but I need to send email using my Yahoo account instead of gmail can you please help me regarding this.
You have to change the values according to yahoo mail
ya i tried using yahoo SMTP details its not working
Ok I will tell you after trying doing it with yahoo
Thanks in advance bro 🙂
hey! it doesnt work on mobile data but works fine on wifi. any solution for this?
i am sending email but its not working?
It is showing me Message sent in toast but when i check gmail account no mail is received. Please help, i even tried different email accounts.
Secondly, what to do if we wish to send a doc file also as an attached document to the mail?
Please help
check config class.. you have to put your actual gmail username and password there
i will give correct username and password but every time got log mes javax.mail.AuthenticationFailedException…
https://www.google.com/settings/security/lesssecureapps
Allow Access Less Secured App
I also gave permission. Never again
this security setting works for me thanks
Hello sir, I had also the same problem. I put my exact gmail account and password but I don’t still get any mails. Even though it tells me that the mail was sent. Please help me. Thank you
The application works properly, however gmail has a security setting which needs to be addressed.
You need to go to your security settings and turn on “Allow less secure apps:”.
Check out this post here for more details : https://www.drupal.org/node/2080923
I did that but still didn’t receive any mail
can u help me ?
really great Thanks for detailed Explanations
Hi , thanks for this tutorial , but i have question : can i make this app accept any types of emails ( yahoo , hotmail , gmail , ….. ) ?
Same question! I already tried several different ways but I wasn’t successful.
I’m trying to send an Email with the Email address the user’s typing in a text field.
Any help is appreciated!
Thx in advance!
thanks for the code. but i am getting error in MainActivity.java file in Error:(3, 30) error: cannot find symbol class AppCompatActivity and Error:(31, 36) error: cannot find symbol method findViewById(int). i did all the dependencies in the exact way. waiting for your reply.
Actually this is the problem with your sdk, update your android studio and sdk. Or you can use Activity or ActionbarActivity instead of AppCompatActivity
yeah!! it is working now. can i have your email, so that i can contact you directly?.
Visit about page 😉
Thank u for your code!! Could you also show how to receive messages using JavaMail API, please? I tried to rework your code, but it wasn’t successful:(
Hello , this message is being translated by Google Translate because I do not speak English, I hope you understand .
Where has :
//Setting sender address
mm.setFrom(new InternetAddress(Config.EMAIL));
//Adding receiver
mm.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
Would actually:
//Setting sender address
mm.setFrom(new InternetAddress(>>email<>Config.EMAIL<<));
For in setFrom method will receive the destination email , and addRecipient is the email that will be sent . I did the tests here and in the original code will send me two emails, a stranger with all system information and another with the message but also strange . When did the tests changing these variables functioned normally sending a well-formatted single email .
not working on my android device even no error in coding……
I implement the same as you have done!
but no message is received in the target email address.
I changed the config file also.
here is the logcat :
01-17 22:19:41.473 12231-12231/polimi.aap.yas.personalhealthrecord E/ViewRootImpl: sendUserActionEvent() mView == null
it says sign in attempt was blocked in my mail
You need to enable POP go to your gmail and from settings enable POP or IMAP
Thank you !!! Your code and this reply helped me a lot to put the application working. It turns out htat the POP/IMAP was turn off on gmail setting.
thanks for the tut..but when i have my mail and pass stored in config.java .what i want is when user uses my app and wants to send a mail to me, im not getting the mail to my mail ,instead it shows like u got a mail from sv53@gmail.com(this is in config file) to the mail which i entered in receipient field .
when a user send a mail using his mail id, i need to get mail to my sv53 mail id, but how to?
If you are having problems disable you anti-virus and check it again…
Also had to allow less secure app in google.
https://www.google.com/settings/security/lesssecureapps
It works !!! Thanks man, God Bless You 🙂
It is showing me Message sent in toast but when i check gmail account no mail is received..
Cool tut, I wish I understood Android Studio better but I am just now teaching myself and could use help on a couple projects. I can only imagine how busy you must be, but if you would/could help me just a bit, I sure would appreciate it! If you are interested, please contact me via admin@mohtech.ca
Thank you in advance!
Mike
Hi mate, first of all i want to thanks to you for this tutorial, im having a problem when i click the send buttom, i got the following output:
03-15 08:40:21.396 3801-4071/ar.com.taxiexpress.taxiexpress E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: ar.com.taxiexpress.taxiexpress, PID: 3801
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.NoClassDefFoundError: ar.com.taxiexpress.taxiexpress.SendMail$1
at ar.com.taxiexpress.taxiexpress.SendMail.doInBackground(SendMail.java:74)
at ar.com.taxiexpress.taxiexpress.SendMail.doInBackground(SendMail.java:21)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
Could you please helpme with this?
Best regards.
Hey,
I get the same error. Can anyone help?
Error: java.lang.NoClassDefFoundError: com.sun.mail.util.MailLogger
You should check the gradle file
(App). If you have written duplicate about mail, it would have shown error message like you.
For example, in your gradle file,
If there are more than a line,
compile javax.javamail.5-
dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
-> this is two lines about javamail.
So delete one of them. 🙂 i solved the problem in this way
hey how to create new java class as u mentioned like config.java, Mainactivity.java etc on android studio 1.5.1. I am new to android coding.plz help
i got error at this line in main.xml
//Creating SendMail object
SendMail sm = new SendMail(this, email, subject, message);
sm.execute();
showing error as cannot resolve symbol,,,,,help me wit this…
Hi ,
I am not able to download your project.
i have some problem
Error:(27, 25) error: package R does not exist
error:cannot resolve symbol variable toolbar,error:cannot resolve symbol variable fab.kindly help in this regards
hi, nice tutorial, i’m got it ^_^
but now i’m to try for receive email, i hope you can help me :’)
thanks
hi i have to design an email client for my project assigned to me can someone help me with the same?
How do i check if email is successfully sent. For example if invalid recipient is used how will i know?
Hello sir, I put my exact gmail account and password but I don’t still get any mails. Even though it tells me that the mail was sent. Please help me. Thank you
I also enabled pop to my Gmail from setting enable pop but still i did not get any mail……please help me to solve this problem
Awsm tuttorial…its working…
in addition to this i want to add extra content with mail(like thanks from our team….) which will be sent to the recipient…and this content shows only when recipient receive the mail….how can i add this extra content with the mail???
please help me to solve this problem
It’s working fine .But whenever i was sending mail getting suspicious mail not allow less security apps ,
how can i achieve that?
Thanks for this blog,It’s helpful!
I want to use a login activity to authentificate the users and after I’ll get a new activity for exemple the inbox and button write new mail!!what can I do for do that idea??thanks in advanced
Hi,
in my app I have an own text as an EditText which I want to send with an email. How can I add my own text instead of typing one in into the “message field” and send this one via email?
Hi same problem for me also. Whenever I filled all the fields ( receipent, Subject, Body ), it show message sent but I am not able to receive the message.
Please help me. Thanks in advance.
make sure you have enabled the settings in your gmail account
It is working perfectly fine. Thanks a lot. I created a new ID my POP and IMAP both are disabled in gmail settings but still it works.
hii i tried this code but am getting error in code can u please send me your code….. rameshec13@gmail.com
Cannot resolve symbol SendMail in the main activity. Please help! SendMail and execute go red.
SendMail sm = new SendMail(this, email, subject, message);
//Executing sendmail to send email
sm.execute()
I am getting below error please help me.I followed all steps as same in this article.
FATAL EXCEPTION: AsyncTask #3
Process: chattm.com, PID: 2280
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getByName(InetAddress.java:289)
at javax.mail.URLName.getHostAddress(URLName.java:487)
at javax.mail.URLName.hashCode(URLName.java:463)
at java.util.Collections.secondaryHash(Collections.java:3405)
at java.util.Hashtable.get(Hashtable.java:265)
at javax.mail.Session.getPasswordAuthentication(Session.java:823)
at javax.mail.Service.connect(Service.java:271)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at chattm.com.SendMail.doInBackground(SendMail.java:95)
at chattm.com.SendMail.doInBackground(SendMail.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getByName(InetAddress.java:289)
at javax.mail.URLName.getHostAddress(URLName.java:487)
at javax.mail.URLName.hashCode(URLName.java:463)
at java.util.Collections.secondaryHash(Collections.java:3405)
at java.util.Hashtable.get(Hashtable.java:265)
at javax.mail.Session.getPasswordAuthentication(Session.java:823)
at javax.mail.Service.connect(Service.java:271)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at chattm.com.SendMail.doInBackground(SendMail.java:95)
at chattm.com.SendMail.doInBackground(SendMail.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: libcore.io.ErrnoException: getaddrinfo failed: EACCES (Permission denied)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:61)
at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getByName(InetAddress.java:289)
at javax.mail.URLName.getHostAddress(URLName.java:487)
at javax.mail.URLName.hashCode(URLName.java:463)
at java.util.Collections.secondaryHash(Collections.java:3405)
at java.util.Hashtable.get(Hashtable.java:265)
at javax.mail.Session.getPasswordAuthentication(Session.java:823)
at javax.mail.Service.connect(Service.java:271)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at chattm.com.SendMail.doInBackground(SendMail.java:95)
at chattm.com.SendMail.doInBackground(SendMail.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Even i’m facing the same issue. this issue is happening when installing application from app-release.apk or app-debug.apk. but it is getting success when i’m directly installing application from studio. please help thanks in advance.
Dude you literaly save my life
Your welcome
itis better to use backend side to send email.for example from your php than your android side.
itis better to send email from your php or server side rather than hard coded this in your java side.
thanks sir ….for the codes but while i am sending the mail is say Message send but no email is received i input the correct receipient and in codes add coreect email and pass also enable allow less secure app but nothing work right
Hi good tuto! if we want to use our server to sendmail, how can we do?
Hi good tuto! How i can use this but with another smtp?
Thanx bro for this tutorial. Here My application works properly but there is a problem. Problem is that:-
Review blocked sign-in attempt….and so On……
So how can we solved this problem……….
I’m waiting for your reply………………
Already,I solved previous problem using “https://www.google.com/settings/security/lesssecureapps”
But this is not a permanent solution please gime me a permanent solution of this topic.
& another problem is………….
If we enter “abcxyzfhkashfhds@gmail.com” this email address. This is not a valid email address. so how we check this email exists or not??????????
Hi every one this code is working fine but still I am not getting any MAIL…….So in this case what should i do?
Please help me………..
work perfectly, thank you for your excellent topic
Could not send email
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.ConnectException: failed to connect to smtp.gmail.com/2404:6800:4003:c00::6d (port 465) after 90000ms: isConnected failed: ENETUNREACH (Network is unreachable)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at info.maildemo.Mail.send(Mail.java:138)
at info.maildemo.MainActivity$SendMail.doInBackground(MainActivity.java:65)
at info.maildemo.MainActivity$SendMail.doInBackground(MainActivity.java:45)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.net.ConnectException: failed to connect to smtp.gmail.com/2404:6800:4003:c00::6d (port 465) after 90000ms: isConnected failed: ENETUNREACH (Network is unreachable)
at libcore.io.IoBridge.isConnected(IoBridge.java:267)
at libcore.io.IoBridge.connectErrno(IoBridge.java:191)
at libcore.io.IoBridge.connect(IoBridge.java:127)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:461)
at java.net.Socket.connect(Socket.java:918)
at java.net.Socket.connect(Socket.java:844)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at info.maildemo.Mail.send(Mail.java:138)
at info.maildemo.MainActivity$SendMail.doInBackground(MainActivity.java:65)
at info.maildemo.MainActivity$SendMail.doInBackground(MainActivity.java:45)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: isConnected failed: ENETUNREACH (Network is unreachable)
i got above error while executing kindly help me.
I have the same problem
Did you resolved it? 🙁
U got the solution ?? please share with me i have same error..
OK. Worked fine.
I placed inside the application method in the manifest. That was wrong. Should be placed outside the application method. Took me a while to solve that ‘bug’ 😉
I mean the staement: uses-permission android:name=”android.permission.INTERNET”
I dont know when i add it with other fragments it crashes everytimes. But instead i add with no fragment just main activity it works. Will you plz show a tut that show if i can add Send Mail with different fragments not just coding with the main activity ?plz
Yes i am also getting same, while using activity its works but with fragment its showing error in line “SendMail sm = new SendMail(this, email, subject, message);”
Could you please help me to resolve this issue ?
Use getActivity(), instead of ‘this’
I followed the procedure as written and all code is same as on site. I am writing recipient email, subject and body for email but the email is not going. My login ID and password is also correct, the account is working and even i am getting progress bar as well as Toast message that “Message Sent”. I don’t understand what is the problem..please help
Awesome work man works great!!1
I am creating an app to register a customer.When a customer register with the system i want to send a welcome email to customer.When i run the app data is added to the database but app is stopped. logcat says about fatal exception.Any one can help me plz?
Thank you
Awesome wrk…After long time i’ve found tat Codes….Thnx
It’s working well in emulator android. I can receive email. Then I tried to install my app in my android device with Wifi connection, it’s working well. But when I use Data Mobile Connection (not Wifi) email not sent. Can you tell me why?
Thanks belal it works perfectly!
Only we need to remember is that enable “Allow less secure apps” setting of
gmail account whose username and password we are passing in Config.java file.
As new to android tutorial like this is like a gift thanks bro!
Need to read emails, inbox, draft, custom folder etc so that I can display them on a listview in my app. It needs to read default android email not gmail. I haven’t found anything except sending emails.
Can you help with this? Willing to PAY $$ for your help. Thanks in advance.
Get an error ” Unfortunattly Apllication is has stopped”
Hlo Bro,
Can you plz tell me tht why the mails are going to the spam?
I want to send the mails to the Inbox.
Its a nice post within few minutes i get it done working.
Its Working Good. Thanks
hey i am getting error in msg.setText(message); , its an exception for notypedeffound exception.kindly help.
It’s working. Thanks!
Please help me
Error:
Error:Execution failed for task ‘:app:preDexDebug’.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk7\bin\java.exe” finished with non-zero exit value 1
what if the email entered do not exist? will the app know it ??
Long story in short “this app works fine on emulator but does not work on real device”
Bro,this app works fine on emualtor,but no email is acctualy sent on when i use real device…I know there is no problem on this code.But i assume something is missing on dependency or something like that,that would make the app work both on emulator and real device.Pls help me brother
Sir is there a way where my app can know whether this email exists or not???
This works great! Any way to add attachment?
it works thanks. But i want to add some extra textfields and how can i include to the code part ?
it showing Message sent but i can’t get any mail so help me out.i fill my credential to config file also.
How to add attchment?
Unable to download any files, Error (429)
This account’s links are generating too much traffic and have been temporarily disabled!
Will you have any alternative links the project can be downloaded from?
If you implement emailing from the android app (or any client side app) like this, your account can be compromised. If I get this app, I can easily decompile the jar and get your Gmail Password. So I suggest not to use this for sending emails.
Thanks a lot buddy
Worked like a charm
it’s really work. What about attach? How to use?
This code will work even without downloading the file.
Just add
compile ‘com.sun.mail:android-mail:1.5.5’
compile ‘com.sun.mail:android-activation:1.5.5’
in build.gradile – dependencies section.
Thanks for the code!
am having a problem
am able to send and receive the mail on my own wifi network and mobile data
but when i use the app for sending mail from a different wifi am not receiving any mail
i tried with 3 of my friends ..they tried to send me mail but it does not work i.e am not receiving emails from their wifi
can anyone help me ?
Hii Sir .. i get this type of error .. how can i solve it please help me.
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
java.net.ConnectException: failed to connect to smtp.gmail.com/74.125.68.108 (port 465): connect failed: ETIMEDOUT (Connection timed out)
When i try the API i get the following error and the message ” App stopped working. Any help.
07-25 14:05:17.123 11187-11270/emailtestapp.myapp1 E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: emailtestapp.myapp1, PID: 11187
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
ASWK…
I try this code but i found one error “javax.mail.AuthenticationFailedException” I enable the Less secure apps permission but still not working again i got same error.
please help.
Hi!
Your code work perfectly!!!
How is it possible to send attachments (Images)?
Showing Null Pointer Exception Error when i have clicked on a button…
Hi, I’m using your library in my project and it’s great.
I have a small inconvenience.
I want to be able to attach a document to my message, but I do not know how to do it.
Is your library capable of attaching a document to the mail?
An apology if my English is not very clear, it is not my native language.
Very good tutorial! Can you show us how to attach a pdf file?
Code Works!!! but first time it takes 5 minute to send a mail and from second time it takes just few minutes. Please help
hi!!I enabled my setting in gmail and allowed less secured apps but it was not delivering any message .can u please send me your code to sravya.gunna007@gmail.com
Thank you so much!!!
Very good tutorial! Can you show us how to attach a pdf file and image file ? please please help me.
Thank you for your code, I’v attached this but it is not working for me generating exception– javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
nested exception is:
java.net.ConnectException: failed to connect to smtp.gmail.com/2404:6800:4003:c03::6d (port 465) after 90000ms: isConnected failed: ENETUNREACH (Network is unreachable)
please help me.
Hi Belal. First of all thanx for the nice tutorial. This is only for sending the email.how to receive the emails?
I want to develop the app like gmail. Can you guide me how to do this? Please help me.
working absolutely fine !
just you have to take care of these
1) add jar files in jar dependencies.
2) allow less secure app in google.
https://www.google.com/settings/security/lesssecureapps
3) enable IMAP
https://mail.google.com/mail/u/1/#settings/fwdandpop
Anyway Thanks sir !
Sending mail working fine only in some mobiles..Its giving error in some phones while trying to send..
checked internet connection even though it is not sending from some phones..
i want to receive email through my app just like contact us field in all other app example flipkart,amazon.etc,i have tried above code but problem with it is I cant receive emails ….I have passed correct details in config file and i have set up email setting then to i cant see emails but i receives toast message saying that message sent….can you please help me with that and help me with receiving mails .
Thanks in advance.
how do I sign up
Can i send the image or pdf file using this? can you tell me please
Thanks for the tutorial. My app works. Thumbs up!
Is this free to use
Very interesting code, what I was looking for, thanks so much, but… unfortunately it doesn’t send any mail.. I try with three of my accounts, but nothing…