In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "springboot how to achieve automatic email sending task", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "springboot how to achieve automatic email sending task" article.
1. Import jar package org.springframework.boot spring-boot-starter-mail 2.5.22. Configuration file
Get QQ Mail's POP3/SMTP service, get the encrypted password, and write the configuration file of springboot
Spring.mail.username=2080038188@qq.com # QQ is not mine.
Spring.mail.password=gzcmhxxybgvbcjil # here is the encrypted password
Spring.mail.host=smtp.qq.com
Spring.mail.properties.mail.smtp.ssl.enable=true # this step is to turn on encryption authentication
3. test
Test in a test class
@ SpringBootTestclass Sprintboot09TestApplicationTests {@ Autowired JavaMailSenderImpl mailSender; @ Test void contextLoads () {SimpleMailMessage mailMessage = new SimpleMailMessage (); mailMessage.setSubject (Hello); mailMessage.setText (thank you); mailMessage.setTo (2080038188@qq.com); mailMessage.setFrom (2080038188@qq.com); mailSender.send (mailMessage);}}
Then send it successfully, your QQ Mail will receive your own message, here is a great sense of achievement!
Key: in my test, there has been bug, looking for nearly half an hour to find, the result is that our springboot configuration file hit an extra space, the naked eye can not see, this kind of error, it is true to find good hard, once suspected is the jar package version or QQ Mail problem, the result is too much worry. Be sure to pay attention to the space problem in the springboot configuration file in the future!
Complex email send @ Testvoid contextLoads2 () throws MessagingException {/ / A complex email MimeMessage mimeMessage = mailSender.createMimeMessage (); / / assemble MimeMessageHelper helper = new MimeMessageHelper (mimeMessage, true); / / body helper.setSubject ("Hello ~ plus"); helper.setText ("Thank you for your crazy talk java series course ~
", true); / / Annex helper.addAttachment (" 1.jpg ", new File (" C:\\ Users\\ 86187\ Desktop\\ 1.jpg "); helper.setTo (" 2080038187@qq.com "); helper.setFrom (" 2080038187@qq.com "); mailSender.send (mimeMessage) } the above is the content of this article on "how to achieve automatic email sending task in springboot". I believe you all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.