This video is over 5 years old now. Watch the updated version here: ruclips.net/video/kLMUS0-PznE/видео.html. It covers the java email topic with the latest steps for generating an app password.
Worked perfectly for me however took a very long time to follow your steps as you code entire blocks at once very quickly using the suggested options in the drop down boxes. Also it would help to review the entire code at the end of the video especially the final imported packages list. I hope this is useful for your future videos but overall good job thanks for your help
holy shit man you helped me so much that low security setting was very hidden, thank you very much. no but for real thank you so much I finally sent an email yes
Nice video and explanation but this shows one more time that you have to write a lot of code in Java for simple things like sending an email. In other languages like PHP sending an email requires ONLY 1 line of code.
PHP is designed to be a web language while Java is totally not but being able to do this is just an extra A lot of Java functionality cannot be found on PHP as well
let's see that one line of code, I have been trying to use PHP to send emails from a database for a school project and ended up using a Java app to do it.
Hi Everyone, In case you are facing any issues with sending email (not specific to gmail, you can use any SMTP server), try to troubleshoot it as follows. - Make sure that the "host", "port", "email-address" and "password" are correct. www.smtper.net/ is a good tool to make sure that you have the correct values since you can use this service to send dummy emails. - If you encounter 'Couldn't connect to host' error, somehow your system is not able to connect to remote email server. This may be because of your antivirus, firewall blocking connection. Add exception rules in firewall or try temporarily disabling them to confirm the issue cause.
If anyone is having problems where the email is sent and seen on the same account used for sending the email, but can't see it on other accounts, use a account that has 2 factor authentication enabled to send email. If you are concerned about the password use "App password" feature in "security" tab of your gmail account to generate random password.
could you plz parse the code here , i am getting this error : javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. though i am using these parameters props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587");
Add the below code to properties if you have exception of javax Could not convert socket to TLS; props.put("mail.smtp.ssl.protocols", "TLSv1.2"); and bro thanks for this video.
Why don't we have JAVA Mail in Java 8 JDK itself ? Why are we adding as third party ? Can we include if we use Maven in this case ? If anyone has done with maven what is the artifact details, please share. Thanks.
sir, when i do the same as you did, i got an error with: Transport.send(message) ,and when i use the same function inside another class as a function i got another problem with Session.getInstance() that it can`t find the symbol and the Session class in this case doesn`t have the function....please tell me what should i do
Awesome work, but is this normal? it takes 8 seconds to send an email. I thought Java is a fast-running language since it compiles lines of codes and doesn't interpret. I'm planning for sending a survey email to all people in my college. I tried only on my 4 emails it took 35 seconds. 3 seconds I think for accessing an array of strings. maybe it has something to do with authentication & other stuff.
Thank you very much sir it helped me a lot. Any idea where can I find a tutorial about mail listener? I wand to be able to intercept every email from an email address. Thank you.
Have you encountered this error when sending the email before by any chance and would you know how to solve it? javax.mail.MessagingException: Could not convert socket to TLS; nested exception is: javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
Hi , Iam getting the following error javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect Please help me on this
I'm getting a class not found exception on the line where I do "Message message = new MimeMessage(session);" and im not sure how to resolve this. Any help is appreciated ty
hi guys could any one of you parse the code here i tried this one it did not work Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("***Myaccount","*****Mypassword****"); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("***Account***")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("***Account***")); message.setText("Test Text"); Transport.send(message); System.out.println("Email sent Successfully !"); }catch(MessagingException e){ System.err.println("Something went wrong !"); throw new RuntimeException(e); } ----------------------------------------------------------------- i get this error Exception in thread "main" java.lang.RuntimeException: javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. v188sm10670600wma.10 - gsmtp at Métier.Debug.main(Debug.java:129) Caused by: javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. v188sm10670600wma.10 - gsmtp at javax.mail.Transport.send0(Transport.java:218) at javax.mail.Transport.send(Transport.java:80) Any suggestion guys ?
help pleas my fire wall already off i need this for a prject i m working on javax.mail.AuthenticationFailedException: failed to connect, no password specified? my password and eamil are correct i double checked them
Interesting tutorials thanks a lot. But i have done the same things but unfortunatelly the e-mail can't be send . I don't know why. May you help me please to resolve this problem? thanks for your understanding
It is because of the Less Secure Apps option in Google Security. By default it's switched off, and when such is like that, you cannot send emails from third party applications, such as the ide you're using.
Hello, I used the same code before. In 2016-2017. I could send more than 1 mail in 1 second. Now he sends 1 mail in 20 seconds. It may have caused an update. I couldn't help, can you help?
Did someone get Exception "Username and Password not accepted"? I'm sure that I'm writing my email account and password correctly and I don't have any security attached to my account.
theres a probelem. when iam changing recepient mail then it doesnt sending any email and showing error like username and password not authenticated. plz help me
Couldn't connect to host => This happened because the program can't access the email server. Make sure your program can access the internet and is not blocked by firewall, antivirus etc.
At first check access to the host via telnet "telnet smtp.gmail.com 587" (javaee.github.io/javamail/FAQ#condebug).If it's ok try to turn off firewall and antivirus (as Genuine Coder replied).I has the same error because my antivirus blocked "dangerous attaches in emails" without any notifications.
This video is over 5 years old now. Watch the updated version here: ruclips.net/video/kLMUS0-PznE/видео.html. It covers the java email topic with the latest steps for generating an app password.
The perfect volume for background music, I can still hear u and focus on what u r doing, and the video gets its good feel
Worked perfectly for me however took a very long time to follow your steps as you code entire blocks at once very quickly using the suggested options in the drop down boxes. Also it would help to review the entire code at the end of the video especially the final imported packages list.
I hope this is useful for your future videos but overall good job thanks for your help
Thanks working fine for me.
if there is security problem write this -
properties.put("mail.smtp.ssl.trust", "smtp.gmail.com");
THANK YOU!!!
Thanks!
Thanks
thankyou so much sir , firstly i got an error because i didn't mention the password, but then it worked ...
Thank you so much! This was such a clean video super good tutorial! Keep up the good work, love from a CS student in Denmark!
Amigo, você é incrivel. Salvou meu TCC. Obrigado e toma esse like!
Great explanation. I'll stay tuned for more tutorials like this.
Greetings from Brazil!
holy shit man you helped me so much that low security setting was very hidden, thank you very much.
no but for real thank you so much I finally sent an email yes
it worked perfectly
THANKS ALOT GENUINE CODER
Good job Bro...
Excellent tutorial
Thanks a lot bro. You explained very easily and now my program is working perfectly.
You are an absolute genius
Very well done, this video actually helps you and you explain everything. Thank you so much for making this video
Very Usefull thanks
Its working perfectly thanks alot brother
U r really good teacher sir
Thank you so much! This was a great video and you explained everything very well!
Thaks this is very useful.
Excellent work nice keep it up bro
Hello, Can you help please? I receive this error on Transport.send(message). "Couldn't connect to host, port: true, 25; timeout -1"
i had the same error , if you solved it , can you help me ?
It would be nice if you would put this code on github. Thanks for all of the hard work.
Great job helped me with my finala project for It talents Bulgaria . Greetings brother. Ako znesh mamichkata mi se eba s toq proekt , Krasi rules
thank you for this awesome video
Thanks alot dear. I got it clear now I will dig more into Java Mail API with your background.
First comment:
thank you so much
Interesting and clearly explained video thanks!
you are the man
Thank you very much very helpful video.
Nice video and explanation but this shows one more time that you have to write a lot of code in Java for simple things like sending an email. In other languages like PHP sending an email requires ONLY 1 line of code.
PHP is designed to be a web language while Java is totally not but being able to do this is just an extra
A lot of Java functionality cannot be found on PHP as well
See robustness not line of code
let's see that one line of code, I have been trying to use PHP to send emails from a database for a school project and ended up using a Java app to do it.
Thank you for the video
Hi Everyone,
In case you are facing any issues with sending email (not specific to gmail, you can use any SMTP server), try to troubleshoot it as follows.
- Make sure that the "host", "port", "email-address" and "password" are correct. www.smtper.net/ is a good tool to make sure that you have the correct values since you can use this service to send dummy emails.
- If you encounter 'Couldn't connect to host' error, somehow your system is not able to connect to remote email server. This may be because of your antivirus, firewall blocking connection. Add exception rules in firewall or try temporarily disabling them to confirm the issue cause.
heyyy! thanks for the tutorial. I just wanna ask if how are we gonna send email to multiple mails with just a click?
I am getting the couldn't connect to host error please tell me how can I fix it
If anyone is having problems where the email is sent and seen on the same account used for sending the email, but can't see it on other accounts, use a account that has 2 factor authentication enabled to send email. If you are concerned about the password use "App password" feature in "security" tab of your gmail account to generate random password.
thank you sir, it work perfectly
Finally got it to work, thank you!
Man, thank you so much! Good tutorial!
thank you this works flawlessly!
could you plz parse the code here , i am getting this error :
javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. though i am using these parameters
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Add the below code to properties if you have exception of javax Could not convert socket to TLS;
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
and bro thanks for this video.
Why don't we have JAVA Mail in Java 8 JDK itself ? Why are we adding as third party ? Can we include if we use Maven in this case ? If anyone has done with maven what is the artifact details, please share. Thanks.
Can you upgrade to run this in Jakartaa and Glassfish? is returning comsunmailimapIMAPProvider not a subtype exception :c
you absolute legend
sir, when i do the same as you did, i got an error with: Transport.send(message) ,and when i use the same function inside another class as a function i got another problem with Session.getInstance() that it can`t find the symbol and the Session class in this case doesn`t have the function....please tell me what should i do
You imported wrong class. Make sure that your imports look like these:
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
It's working, thank you so much sir.
Awesome work, but is this normal? it takes 8 seconds to send an email. I thought Java is a fast-running language since it compiles lines of codes and doesn't interpret. I'm planning for sending a survey email to all people in my college. I tried only on my 4 emails it took 35 seconds. 3 seconds I think for accessing an array of strings. maybe it has something to do with authentication & other stuff.
Really clear. Thank you.
like how to send an attachment is there any set() value to be given?
After trying so many codes from different cannel , finally it's really happening ,I am able to send mail using Java, Thanks a lot( ◜‿◝ )♡🥰
great explanation, keep it up!!!!
Use quieter keyboard. But great vid!
Is this only for Gmail ? can I use outlook email as a sender?
great video man !!!
Thank you.
halo sir, for sending the mail it takes 1-2 minute ? im using your github but the result in performance is different.
Thank you very much sir it helped me a lot. Any idea where can I find a tutorial about mail listener? I wand to be able to intercept every email from an email address. Thank you.
🔥thanks.
Great video! It was very well explained! TOP!
class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first.
i am getting this error in the Transport block
i got the same error went back and look like i had the STARTTLS wrote wrong here the correct one properties.put("mail.smtp.starttls.enable", "true");
Have you encountered this error when sending the email before by any chance and would you know how to solve it?
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
I wrote this code in net beans and it worked, but when I wrote the same code in eclipse it gave me exception error..... why? or what should I do??
Hi ,
Iam getting the following error
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
Please help me on this
Thank you so much !
I am getting this issue "Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1;" please help me to find out.
Thanks Alott Dude!!!
I'm getting a class not found exception on the line where I do "Message message = new MimeMessage(session);" and im not sure how to resolve this. Any help is appreciated ty
yea im getting the same problem too for some reason
I feel like I've seen your name from somewhere...have we met my dude?
Great tutorial, thank you so much!!
In case that you want to send email via office 365 with java app. Is this the same code?
Everything works fine in my localhost, but when I configured in my live server it sending mail after 1 to 2 (too slow)minutes. kindly Help🙏🏻
PasswordAuthentication is outdated. You should use the 0Authentification from google which is more secure
Thanks a lot for the info. I didn't know about 0Auth before. I will surely check it and maybe make an updated video with it.
Super helpful!
OMG i did it! Thank you!
I also did it!
hi guys could any one of you parse the code here i tried this one it did not work
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("***Myaccount","*****Mypassword****");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("***Account***"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("***Account***"));
message.setText("Test Text");
Transport.send(message);
System.out.println("Email sent Successfully !");
}catch(MessagingException e){
System.err.println("Something went wrong !");
throw new RuntimeException(e);
}
-----------------------------------------------------------------
i get this error
Exception in thread "main" java.lang.RuntimeException: javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. v188sm10670600wma.10 - gsmtp
at Métier.Debug.main(Debug.java:129)
Caused by: javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. v188sm10670600wma.10 - gsmtp
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
Any suggestion guys ?
could you also put this on github?
thx u very much!!!:)))
Thanks, it helps me a lot !!
Can you help me out
It shows that javax.mail.Session is not accessible
may I know what should I do?
Can u make a video how to style according with css using javafx facing many problem . plz its request
well explained, thank you
help pleas my fire wall already off i need this for a prject i m working on
javax.mail.AuthenticationFailedException: failed to connect, no password specified?
my password and eamil are correct i double checked them
Interesting tutorials thanks a lot. But i have done the same things but unfortunatelly the e-mail can't be send . I don't know why. May you help me please to resolve this problem? thanks for your understanding
It is because of the Less Secure Apps option in Google Security. By default it's switched off, and when such is like that, you cannot send emails from third party applications, such as the ide you're using.
thanks man
Can i use this code in web services as like when response getting as failure then failure response had been send through mail.please help me.
It's work in the ide perfectly but w
I make a runnable jar it doesn't work the message won't send, any help please
Doesn't seems to work with JDK11 and Eclipse
Thank you sir😊😊
thanks a lot
Hi, im getting the error java.lang.NoClassDefFoundError: java/mail/Address. i cant seem to find any fixes online.
Thanks
same
me too
www.oracle.com/java/technologies/downloads.html
@@tommygokes Thank you, good sir
@@tommygokes you are a legend
having trouble with the authenticator. says something about incomparable types and i have written as you have.
solved , use ' import javax.mail.Authenticator ' instead of ' java.net.Authenticator '.
i tried importing the javax.mail thing into the eclipse package, but it says it can't access it. what do i do?
you may have not putting the jar in the correct place
Hello, I used the same code before. In 2016-2017. I could send more than 1 mail in 1 second. Now he sends 1 mail in 20 seconds. It may have caused an update. I couldn't help, can you help?
I can implement CSS in this API?
Hi every one, i havw facing issues like(javax.mail.MessagingException: Could not convert socket to TLS;) please give me some solution .
Did someone get Exception "Username and Password not accepted"? I'm sure that I'm writing my email account and password correctly and I don't have any security attached to my account.
can you please guide me to send bulk mails like this way
sir what if the recepient mail does not exist ? how to check it in the program?
theres a probelem. when iam changing recepient mail then it doesnt sending any email and showing error like username and password not authenticated. plz help me
How find any probleme with send exception . Try with adding the flowing line
properties.put("mail.smtp.ssl.enable");
And
properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
And think you for the video it s rely helpful
Did not work for me:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Authenticator
same :(
Had the same problem first. Which JAva-Version do you use? In 1.8 it worked fine for me.
@@Falconbyte using jdk11 here.
shows this error:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 587; timeout -1;
Couldn't connect to host => This happened because the program can't access the email server.
Make sure your program can access the internet and is not blocked by firewall, antivirus etc.
At first check access to the host via telnet "telnet smtp.gmail.com 587" (javaee.github.io/javamail/FAQ#condebug).If it's ok try to turn off firewall and antivirus (as Genuine Coder replied).I has the same error because my antivirus blocked "dangerous attaches in emails" without any notifications.
I keep getting this error: Must issue a STARTTLS command first.
add this properties.put("mail.smtp.starttls.enable", "true");