Spring Boot | Sending Email with
Vložit
- čas přidán 12. 11. 2018
- This video explains you how to send an email with HTML body in spring boot using FreeMarker Template
#JavaTechie #FreeMarker #Email #SpringBoot
GitHub:
github.com/Java-Techie-jt/spr...
Blogs:
javagyanmantra.wixsite.com/we...
Facebook:
/ 919464521471923
Like and Subscribe - Věda a technologie
Great tutorial, its awesome concept for the email service.
superb video dude keep it up
thank you very much. it will helpful for me.
Good tutorial about how to implement Freemarker. Thank you.
Awesome tutorial thank you so much bro
Life saver!!!
Thank you, excellent
Great video!
How could I insert images that I have in my folder resources/templates/images/? When I send the email, it doesn't recognize the image, it can't find it.
Awesome bhai..
Great !!!
Thank you very much!
How to add subject with dynamic data inside the html template itself ?
that was very helpful
Can you please tell how to add username,password,port and host in the code as you have added that in application.properties but not in code. Thanks for the video . Nice explanation
Simply Brilliant
I really want to thank you.
I liked your teaching methodology and viewing every relatable video from yesterday
Keep up the good work
How to write inline images through this code bro.
Need one help .. Can i send email for different languages also ?
awesome
How to add an image in the mail body, I am unable to display an image in the mail body
Excellent
how you added application.propertise file deatils like port no, password . Please Explain
in this video clip 16.09 you displayed body section ..i dont know where to add that body function..pls let me know sir
template
getting this error : javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;
Please google it , I assume it occurs as configure email disabled for less secure app
please help me im getting error
"timestamp": "2020-05-29T05:46:22.368+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'text/plain;charset=UTF-8' not supported",
Share your request structure please
Also change context type to application/json in postman then try sending request
Type freemarker.template.Configuration not present
facing this error
Sir I am getting authentication error while hitting send from postman ,what I need to do?
Please copy paste error message
Hello I need help how to add 7:43
im getting this error "535-5.7.8 Username and Password not accepted" , how can i fix this
Verify your email credential
Hello sir
I want to add the email templates like this using servlet how can i do sir please guide me sir.
Please mail me sir i will give some amount also if you could clear this one sir
i get mail with content as
what have i done wrong,
aslo had set (msg,MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,StandardCharsets.UTF_8.name())
Could you please import my code then compare it
Thanks
Hello I need Help Regarding how to send url with template in variable in above same example as button
Didn't get you ? Let me know if I understand correctly
You want to display url as a button in your template correct ?
@@Javatechie yes bro
like confirm/verify like that
Just add href in button .
waiting your reply..if once i run the local host with correct page name its re direct some login page but i dont know its mapping from where in the project .. note: am using linux os ......
Did you add spring starter security dependency in your project
how to add ..spring security bro ..
...@@Javatechie
Am asking you did you add any security related dependency ?
Yes sir...am added correctly
Great tutorial, however, there is no need to create a configuration class, you can just write spring.freemarker.template-loader-path= your path in the application.properties
what about if templates are in DB?
@@mikaelangel76 look into StringTemplateLoader to get data from db
How can I add rows dynamically in the email template?
For that you need to add data dynamically to your ftl file .
Let's say I want to send list of objects to ftl file
So from DB suppose I get two records so in ftl while iterate it will map two record to it and same Will be display as part email response
Same way if in my DB , more than 2 record is there then it will map to ftl as a separate row and it will display as mail body .
Feel free to ask your doubts .if not clear
@@Javatechie Thanks. That was exactly my use case. I was able to resolve it using in ftl file
Cool already I uploaded video spring boot with freemarker template .any Time you can refer it
@Data i used for what it is lombok given annotatio n or what
got it its for setter and getter and @AllArgsConstructor generates a constructor with 1 parameter for each field in your class and @NoArgsConstructor will generate a constructor with no parameters am i rit
in application.properties u mention username and password how to send without knowing sender password
"Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted.
you need to enable on the mail box you use the acces to the less secure application :)
How to apply.bootstrap for freemaker template plz upload a video regards that thing.
Good catch Venkata , bootstrap will only support if you add it in tag . outside import won't work ...
when i am sending the request from postman then i got username and password not accepted error
In properties file check whether your Gmail credential is proper or not ?
@@Javatechie sir in mine to this error is coming and im giving my email and pass correct
@JavaTechie Could you please tell the logic of attaching image in html but should be working on server also?
Image path need to be specific from server directory
@@Javatechie yes I did that but in outlook after updating setting also is saying linked image is not present?
@@Javatechie can you please help me on how to pass inline image in template
@@Javatechiewhat about if you want to send notification email to for example mulitple client email accounts? Do you have a tutorial for that?
You can do that here only by just including an array of email id
How can the senderId (emailId)be dynamic, what will be the best way to design so that the senderId(emailId) can be dynamic
Load it from properties file if you don't want to hardcode it in code
in that case i think we need a factory class, to handle the same? so if the senderId is now of different conpared to the earler one, in first place mail was sent using outlook now it may be gmail in that case the SMTP host may differ
i gave the correct credentials but i am getting javax.mail.AuthenticationFailedException . Please help me out.
Check is there any space added in properties
@@Javatechie yh i figured it out. I enabled less secure apps to access my mail. Thanks for your reply.
I want to ask, why can't I send an email and not display any messages? I have added spring security
thank you
Are you using spring boot email starter ?
@@Javatechie What do you mean by this?
org.springframework.boot
spring-boot-starter-mail
yes, I copied the dependency from your github
@@rezaandika1554 could you please tell me your error , because spring security and email both are different context
Can you please tell how can pass inline image in ftl file
Could you got the result?
will I send mail from this springboot and using angular
Yes
@@Javatechie can u pls help by sharing an angular sample code If U have, with this implementation? or any video link then also its ok.
is there a way to add a signure as a logo under the text ?
Yes you can , in ftl file just add footer as a signature
@@Javatechie i mean would i have to add it to my map for dynamic binding or it can just be refereed to the path where its located. Thank you man , i attempt it with img src and the path and it didnt work so i would appreciate if you could explain how to refer to an image -> also i am sending it to outlook so it should be done so that embed image appears successfully there
it worked by referring to ClassPathresource and using addliner from MimeMessageHelper , then in template referring to content id
My apologies for another question, but if i do not need dynamic binding and simply need a html content, what can i use instea of freemarker to just refer to my template and avoid creating configuration class
Then in simple mail subject you just need to add HTML tag
No need to use freemarker template
Getting SendFailedException(the address is not a valid RFC 5321 address)…..500internal
Check did you enable less secure app in your Gmail
sir now its shows white label error ..get method not found
Check proper url mapping ...
i did not change any code from your githup code..
just i import and run the code ..
sir if you don't mind..
give me your mail id ..
i will send my problem and error correctly ..
@@Javatechie
Please forward to javatechie4u@gmail.com
Hi, I am getting 501 error javax.mail.jar connection failed. Please help ...
Did you enable less secure app in your Gmail settings ?
Yes!!!
Actually I haven't added mail dependency in starting so added this jar through build path.Is this the cause because m getting javax.mail connect failed error.
Now any error you are getting
No errors resolved
can anyone help me with sample angular code to implement this with any angular project? pls help. Thanks in advance.
Frontend you want angular and backend as it is ?
@@Javatechie yes sir . pls help. Thank u
@@ExploringTheLife2.0 okay I will share poc for this in weekends
@@Javatechie Thank u so much. If possible then pls make video. It will be very helpful for all.
@@Javatechie have u made poc? share on narvekaromkar16@gmail.com
how can send a multiple mail in postman throu
Sending multiple mail to single user or single mail you want to send multiple user
Could you please elaborate more about your requirement
i want to send a mail to multiple users at a time using postman tool
@@learnjavatechno very simple in helper.setTo(new String[]{"mail I'd 1","mail I'd 2"})
Like this you can set else from post man send list of email and then iterate it in service and pass it to helper.setTo(email)
Rather than liking the appreciation comment try answering some questions in comment box.Not trying to be rude just a suggestion
I always respond to comments, sometimes I might miss some messages which are not displayed further on top so that could be the only reason I missed .
video is not working
It works well in the localhost but when I change to the https domain it doesn't work. Do you know why?
no am not sure need to check
@@Javatechie ok after check. Please help to answer. thanks
nice video!!
How can we add image to an .ftl ? thanks
You need to add inline image as byte[]
@@Javatechie thank you, do you have any exemple ?
i getting Duplicates when sending mail
Check in code somewhere you are calling send email twice or may be send email execute inside a loop .
Cross verify once please
@@Javatechie ty i find out that i calling the same function twice
Getting 404????
Check the url , also verify whether spring boot able to scan your beans or not
Code is not working. I am facing the issue inspite of using right username and password. {
"timestamp": "2020-12-22T16:15:59.514+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 support.google.com/mail/?p=BadCredentials p15sm21627304pgi.40 - gsmtp
",
"trace": "org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 support.google.com/mail/?p=BadCredentials p15sm21627304pgi.40 - gsmtp
\tat org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:438)
\tat org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:359)
\tat org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:354)
\tat com.javatechie.email.api.service.EmailService.sendEmail(EmailService.java:50)
\tat com.javatechie.email.api.SpringBootEmailFreemarkerApplication.sendEmail(SpringBootEmailFreemarkerApplication.java:29)
\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
\tat sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
\tat java.lang.reflect.Method.invoke(Unknown Source)
\tat org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:215)
\tat org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:142)
\tat org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
\tat org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
\tat org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)
\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
\tat org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
\tat org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
\tat org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
\tat org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
\tat java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
\tat java.lang.Thread.run(Unknown Source)
Caused by: javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 support.google.com/mail/?p=BadCredentials p15sm21627304pgi.40 - gsmtp
\tat com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
\tat com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
\tat com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:780)
\tat javax.mail.Service.connect(Service.java:366)
\tat org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:515)
\tat org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:435)
\t... 58 more
",
"path": "/sendingEmail"
}
Your problem has been solved or not ?
please answer
Hi
Lots of fixes to be done on the code you have that you dont even create in front of us. Just copy paste and then explain some of it and the other "it all looks good". It's a big no from me, thanks for wasting 40 minutes of my life.