Send Email Using Spring Boot | Gmail SMTP | Java Mail Sender

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys what's up welcome back to another video so in this video i'm going to show you how to send a simple email using springboot so for that let me quickly create one springboot project so just go to the spring starter and just go to the spring initializer here and choose the project maven language java and keep this default and let me give some group id let me call it urgent codes and give some artifact id and let me call it spring email demo and just give some description and just keep this default and i have the email 11 version so if you have 8 or 16 choose accordingly and we just need to add one dependency and let me call it java mail sender and if i just click generate so this will generate the j file so we just need to go to the file location and extract wherever you want so just click on extract all so let me just extract in my desktop so let me just choose the desktop and select the folder and click on extract so this will extract the springboot application so once you extract that so just open your id so i will be using the intellij so if you have comfortable with measurements or eclipse so you can go with that as well so just click on open and open the project so just choose this project so this will open our springboard project so once all the dependencies are installed so just go to this source main and inside the resources just go to this application.properties and we need to give some configuration inside here so we will be using the gmail smtp you can also use amazon ses service as well so for here we will just give the configuration for gmail smtp for that just type this spring dot mail and let me copy this one and just type the dot host and the host is smtp.gmail.com and also paste that and just type the port so port is basically 587 and let's paste that again and just give the username so we will give the username of the sender after some time and just keep the spring.mail dot password so we will be generating the password as well and also give the properties properties dot mail dot smtp dot a u t h equals to true and let me just copy the same thing here and just write the mail.smtp.start.tls.enable equals to true so once you do this you just need to go to the email from which you want to send the email so let me just go to my email and just click on this manage your google account so down here you can see the security here so for using this app password so we just need to use this app password you need to have the twisted verification so once you do the two step verification with your mobile or whatever the otv so just click on this app password and you just need to give your password here and just click on next so you can see here we just need to select this app and click on other so you just need to give something like spring email demo and click on generate so this will generate the password basically so just copy this password and we just need to go to the intellij here and paste the password here and also give the username email so it's basically your email from which you want to send the email so once we have the configurations just go inside this java and inside here we just need to create one class and let me call it email sender service so we just need to annotate this with service annotation and inside here we just need to auto wire the java mail senders interface for that just type the private java mail sender and just give the mail sender here and we need to create one method let me call it send email send email and inside here we just need to give some parameters so let me just give a string to email and also we just need to give the subject so it's basically a subject of email and also we just need to give the body of email so inside here we just need to give one class so it's a simple mail message class and give message equals to name and just type the simple mail message so this will create the object so just type the message dot set from so this is basically a sender email so we just need to give the sender email so let me just type arjun gotham 8877 at the gmail.com so it's a sender email and just give the message dot set to just type set to and just type that to email and also the message dot set text so it's basically a body and also we just need to give the subject so it's a set subject and give the subject inside here and also we just need to give the mail center dot send and we just need to send the message and after doing this we just need to give some message here so let me just type mail sent success fully and just type dot and also we just need to go inside the spring email demo application here and inside here we just need to annotate with one event listener so just type event listener and inside here we just need to give the application read event dot class and at the top here we just need to auto wire the email sender service class as well so for that just type the auto wired and just type the private email sender service and let me call it sender service and down here we just need to write one method let me call it void send mail and inside here we just need to give the sender service dot send email and we just need to pass the parameter so to email is basically a receiver email so just type the receiver email address and also type the subject so this is basically a subject of the email so this is subject or you can write any subject and also we just need to provide the body as well so this is body of email and once we do this we just need to right click here and run our application so you can see the output here mail send successfully to verify so i just need to go to my receiver email so let me just go to this email here and if i just go to my gmail so you can see here this is the email which i have just received so this is how you send the simple email using this springboot application so if you like my video don't forget to like share and subscribe
Info
Channel: Code With Arjun
Views: 136,697
Rating: undefined out of 5
Keywords: spring boot email sending example, send email using spring boot, spring boot, java mail sender, spring mail sender, smtp, send email using gmail spring boot, CodeWithArjun, codingwithajun, ProgrmmingWitharjun, arjunprogramming, programming, codes, Codingwitharjun, code with arjun java, code with arjun spring boot, code with arjun full stack, codewitharjun email java, coding, code with arjun email using spring, code with arjun, codewitharjun, java, email using smtp, spring
Id: ugIUObNHZdo
Channel Id: undefined
Length: 7min 44sec (464 seconds)
Published: Fri Jul 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.