How to send email using gmail SMTP server directly from your Android App?

  Рет қаралды 17,505

Programmer World

Programmer World

2 жыл бұрын

In this page, it shows the steps to create method to send email directly from your Android App without using the mail clients (such as gmail client or outlook App).
This code uses gmail smtp server to send the email.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details of this video are posted in the below link:
programmerworld.co/android/ho...
However, the main Java code is copied below also for reference:
package com.programmerworld.sendemailapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonSendEmail(View view){
try {
String stringSenderEmail = "SenderEmail963@gmail.com";
String stringReceiverEmail = "receiveremail963@gmail.com";
String stringPasswordSenderEmail = "Test*123";
String stringHost = "smtp.gmail.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", stringHost);
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true");
javax.mail.Session session = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(stringSenderEmail, stringPasswordSenderEmail);
}
});
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(stringReceiverEmail));
mimeMessage.setSubject("Subject: Android App email");
mimeMessage.setText("Hello Programmer,

Programmer World has sent you this 2nd email.

Cheers!
Programmer World");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Transport.send(mimeMessage);
} catch (MessagingException e) {
e.printStackTrace();
}
}
});
thread.start();
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
--

Пікірлер: 67
@myclassroom1649
@myclassroom1649 2 жыл бұрын
Thanks A lot man Finally I found Really grateful video I stuck for whole day and you solve my problem Thx a lot .. : )
@theunwrittenquote
@theunwrittenquote Жыл бұрын
LOTS OF RESPECT AND LOVE FOR THIS ♡
@sebastianbraga
@sebastianbraga Жыл бұрын
Really helpful. Thank you
@gurwindersingh-by5iw
@gurwindersingh-by5iw 10 ай бұрын
Thank you you save my day
@wj-nr7bx
@wj-nr7bx 6 ай бұрын
this help me alot i love u so much
@hashanmadusanka6128
@hashanmadusanka6128 3 ай бұрын
Thank you so much
@hayabusa_lonely
@hayabusa_lonely 8 ай бұрын
Thank you very very match
@thanhnhan8957
@thanhnhan8957 2 ай бұрын
Thank you
@phantomkahn4696
@phantomkahn4696 Жыл бұрын
This worked perfectly after using app password, thank you so much!
@josealzugaray17
@josealzugaray17 Жыл бұрын
how did you do it? It does not work for me uu
@phantomkahn4696
@phantomkahn4696 Жыл бұрын
@@josealzugaray17 what error do you see?
@ariefariefshamsuddin350
@ariefariefshamsuddin350 Жыл бұрын
How did you do it, still does not work for me
@TirthShah133
@TirthShah133 10 ай бұрын
Can you please guide me on App password method? Thanks
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
Please refer to the below: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
@chisomemmanuel6160
@chisomemmanuel6160 2 жыл бұрын
First time commenting in my life 💕💕 Please can you make the one that'll send one particular email message to every user of my android app maybe through firebase
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
Adding all the receipients in the mimeMessage will easily send one message to all the people in one go: mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(stringReceiverEmail)); For reference, the complete source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@chisomemmanuel6160
@chisomemmanuel6160 2 жыл бұрын
@@ProgrammerWorld Thanks 😊 man
@experimentoselectricosdeju6882
@experimentoselectricosdeju6882 Жыл бұрын
It works June 2023; required 2 steps authentification gmail Sender account + create app passwords for devices
@nurulizzatizulkepli6728
@nurulizzatizulkepli6728 Жыл бұрын
its not work for me.. can you fixed my code?
@nurulizzatibintizulkeplist6275
@nurulizzatibintizulkeplist6275 Жыл бұрын
can you help me.. im not work
@TirthShah133
@TirthShah133 10 ай бұрын
Can you please guide me on 2-step authentication and App password method? I tired it already but didn't work. Thanks
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
Please refer to the below: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
@ltchanu7646
@ltchanu7646 Жыл бұрын
It work in 2023.4.29🤗🤗🤗 Thank you.
@badreddine4296
@badreddine4296 Жыл бұрын
How did it work cause the less secure app is not available anymore?
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
You can check the below: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
@annetak693
@annetak693 Жыл бұрын
As of January 2023 this method works wonderfully only on the test versions. But once the version is uploaded to googleplay store, people who upload the version can't sent the messages... or to be more exact the messages never arrive. Never figured out the problem. Any updates would be very welcomed!
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
I think App Password approach may be required for authentication. Below may help: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
@ashishwilson7187
@ashishwilson7187 2 жыл бұрын
not able to get mail do this as per google update based on 30 may 2022
@SamuelHernandez-pd9kj
@SamuelHernandez-pd9kj 2 жыл бұрын
Same issue :(
@song-mt6bn
@song-mt6bn Жыл бұрын
something?
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
Below may help: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
@mudasirkhan8058
@mudasirkhan8058 2 жыл бұрын
i have error my Session and MimMessage Library is not import javaFx
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
I hope below dependencies are implemented in the gradle file. implementation 'com.sun.mail:android-mail:1.6.6' implementation 'com.sun.mail:android-activation:1.6.7' Also, please check that below libraries are imported in your Java file. import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; For reference, the complete source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@TechnicalYarana
@TechnicalYarana 2 жыл бұрын
sir i got it issue in my project what is javax.mail.Session 08:45
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
javax.mail.Session is to create session that is an instance of email client in your App using the properties, such as hostname, password, etc. I hope above explanation helps. For reference, the complete source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@KnowledgeTV143
@KnowledgeTV143 Жыл бұрын
We need to add jar file in classpath?
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
Not sure about the Jar file you are referring. But android-mail dependencies needs to be added in the Gradle file: implementation 'com.sun.mail:android-mail:1.6.6' implementation 'com.sun.mail:android-activation:1.6.7' For reference, complete source code and details shown in this video is also shared in the below link: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@mannguyen5781
@mannguyen5781 8 ай бұрын
I did, but I encountered a "Messaging Exception" error. Could you help me solve it, please? thank you so much.
@ProgrammerWorld
@ProgrammerWorld 8 ай бұрын
Check the updated version of this tutorial in the below. It may help: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
@vulcatechdev
@vulcatechdev 3 ай бұрын
Love it, is there some way to send files?
@ProgrammerWorld
@ProgrammerWorld 3 ай бұрын
To send the files call setContent method on the mimeMessage object. Something like below: mimeMessage.setContent(MimeMultipart) I will try to bring up a separate tutorial on this. programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/
@prafuldeshmukh1178
@prafuldeshmukh1178 Жыл бұрын
i was using this email send method and i have implemented this in my firebase project it worked well for some days and then google has suspended my account by saying this account was using to send spam messages does anyone knows how this happens
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
It seems like there is limit for sending number of emails with this approach (limit imposed by google for security and fare use reasons). This limit as far as we know is 100 emails at a time and 500 emails in a day. Anything beyond this may make Gmail to suspend your account temporarily. For reference, details shown in this video is also shared in the below link: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@user-fd1yu7rc7c
@user-fd1yu7rc7c 6 ай бұрын
wow its work 2024
@user-ym7tj3gk1b
@user-ym7tj3gk1b 5 ай бұрын
what version of android studio did you used?
@user-fd1yu7rc7c
@user-fd1yu7rc7c 5 ай бұрын
@@user-ym7tj3gk1b Android Studio Giraffe | 2022.3.1
@Pasa4009
@Pasa4009 Жыл бұрын
I designed an app that shows my location information, I will be glad if you can help me how to write a code to send my location information as gmail.
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
Refer to my below pages. It may help: programmerworld.co/android/how-to-open-and-send-email-using-the-native-client-directly-from-your-android-app-source-code/ programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@Pasa4009
@Pasa4009 Жыл бұрын
@@ProgrammerWorld thank you Professor
@rushikesh3363
@rushikesh3363 9 ай бұрын
Your project title?
@manibala5799
@manibala5799 2 жыл бұрын
Sir I had run your program successful with changing of sender and reciver mail I'd and password but I can't get mail when press send mail button pls help me....I will send my project to your email
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
Complete source code of this app is shared in the below page. Please check. programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@manibala5799
@manibala5799 2 жыл бұрын
@@ProgrammerWorld it's done but I only change tha sender reciver mail I'd and password but mail not send
@manibala5799
@manibala5799 2 жыл бұрын
I send you link can you check it plssss
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
Kindly check whether the email service provider (gmail account) permits 3rd party Apps to access the Apps or not? If it is allowed then it should work. Also, check the code provided by us at: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ If issue still persists then copy your code here. We will check.. Cheers Programmer World programmerworld.co -
@vanisridhar5509
@vanisridhar5509 2 жыл бұрын
Bro, did you rectified this problem??
@tournamentkiller5778
@tournamentkiller5778 2 жыл бұрын
Sir now this is not working properly please make new video
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
Yes, google has restricted the access to less secured Apps from June 2022 onward. Now, an app password can be used to login. We will try to come up with an updated video on this subject soon. support.google.com/accounts/answer/185833 For reference, the complete source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ Cheers Programmer World programmerworld.co -
@tournamentkiller5778
@tournamentkiller5778 2 жыл бұрын
@@ProgrammerWorld but sir I created in kodular perfectly working sir
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
Nice 👍
@tournamentkiller5778
@tournamentkiller5778 2 жыл бұрын
@@ProgrammerWorld thanks sir I have a KZfaq channel technical yarana once check please
@yeowsongjie8186
@yeowsongjie8186 Жыл бұрын
@@ProgrammerWorld Sorry sir, is the video uploaded? Because i need to use it in my FYP ... Thank you so much sir
@sendcenter7002
@sendcenter7002 Жыл бұрын
I just got the codes. mail I wrote my own e-mail address, I edited it but it doesn't work
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
You can check below also: programmerworld.co/android/how-to-create-your-custom-gmail-client-android-app-using-the-new-googles-app-password-approach-for-authentication-api-34/ Cheers Programmer World programmerworld.co -
Send Email from an Android Application
5:50
Mafia Codes
Рет қаралды 10 М.
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 151 МЛН
OMG🤪 #tiktok #shorts #potapova_blog
00:50
Potapova_blog
Рет қаралды 18 МЛН
1 or 2?🐄
00:12
Kan Andrey
Рет қаралды 33 МЛН
Selenium - how to verify if correct page is loaded or not?
5:03
Programmer World
Рет қаралды 43
Send Email using Intent - Android Studio - Kotlin
11:25
Atif Pervaiz
Рет қаралды 9 М.
3 - RC Low-pass Filter, Simulink Demo
6:28
Embedded Classroom
Рет қаралды 1,8 М.
Osman Kalyoncu Sonu Üzücü Saddest Videos Dream Engine 170 #shorts
00:27