{"id":323249,"date":"2021-05-17T15:00:34","date_gmt":"2021-05-17T15:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=323249"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=323249","title":{"rendered":"\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/580\/984\/f44\/580984f44cd92b01387fad0bded75f29.png\" width=\"780\" height=\"439\"><figcaption><\/figcaption><\/figure>\n<hr>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 <a href=\"https:\/\/www.javadevjournal.com\/spring-boot\/\"><u>\u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0441\u0435\u0440\u0438\u0438 \u043f\u043e Spring&nbsp;Boot<\/u><\/a> \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c&nbsp;\u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0418\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring. \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0432\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SMTP \u0434\u043b\u044f Gmail (\u0438\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0443 Gmail \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b). \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 JavaMailSender \u0432 Spring&nbsp;Framework \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, \u0430 <a href=\"https:\/\/www.javadevjournal.com\/spring\/spring-boot-auto-configuration\/\"><u>Spring&nbsp;Boot \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443<\/u><\/a> \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f.<\/p>\n<h3>1. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Maven<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Spring Boot \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 spring-boot-starter-mail \u0432 \u0444\u0430\u0439\u043b pom.xml. \u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>pom.xml<\/code>:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt; \t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt; \t&lt;artifactId&gt;spring-boot-starter-mail&lt;\/artifactId&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<h3>2. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0447\u0442\u044b \u0434\u043b\u044f <em>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring&nbsp;Boot<\/em>:<\/p>\n<pre><code class=\"java\">spring.mail.host=smtp.gmail.com spring.mail.port=587 spring.mail.username= gmail user name spring.mail.password= your password spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0443 Gmail. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u0438\u0445 \u0441\u0432\u043e\u0438\u043c\u0438<\/p>\n<h3>3. \u0421\u043b\u0443\u0436\u0431\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b<\/h3>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043b\u0443\u0436\u0431\u044b \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0447\u0442\u043e\u0432\u043e\u0439 \u0441\u043b\u0443\u0436\u0431\u044b \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430\u0448 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">@Service public class DefaultEmailService implements EmailService {   @Autowired  public JavaMailSender emailSender;   @Override  public void sendSimpleEmail(String toAddress, String subject, String message) {    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();   simpleMailMessage.setTo(toAddress);   simpleMailMessage.setSubject(subject);   simpleMailMessage.setText(message);   emailSender.send(simpleMailMessage);  }   @Override  public void sendEmailWithAttachment(String toAddress, String subject, String message, String attachment) throws MessagingException, FileNotFoundException {    MimeMessage mimeMessage = emailSender.createMimeMessage();   MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);   messageHelper.setTo(toAddress);   messageHelper.setSubject(subject);   messageHelper.setText(message);   FileSystemResource file = new FileSystemResource(ResourceUtils.getFile(attachment));   messageHelper.addAttachment(\"Purchase Order\", file);   emailSender.send(mimeMessage);  } }<\/code><\/pre>\n<h3>4. \u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 REST, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u0434. \u0423 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 REST \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430. \u0421\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">package com.javadevjournal.controller;  import com.javadevjournal.email.service.EmailService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.mail.MailException; import org.springframework.web.bind.annotation.*;  import javax.mail.MessagingException; import java.io.FileNotFoundException;  @RestController @RequestMapping(\"\/email\") public class EmailController {      private static final Logger LOG = LoggerFactory.getLogger(EmailController.class);      @Autowired     EmailService emailService;      @GetMapping(value = \"\/simple-email\/{user-email}\")     public @ResponseBody ResponseEntity sendSimpleEmail(@PathVariable(\"user-email\") String email) {          try {             emailService.sendSimpleEmail(email, \"Welcome\", \"This is a welcome email for your!!\");         } catch (MailException mailException) {             LOG.error(\"Error while sending out email..{}\", mailException.getStackTrace());             return new ResponseEntity&lt;&gt;(\"Unable to send email\", HttpStatus.INTERNAL_SERVER_ERROR);         }          return new ResponseEntity&lt;&gt;(\"Please check your inbox\", HttpStatus.OK);     }      @GetMapping(value = \"\/simple-order-email\/{user-email}\")     public @ResponseBody ResponseEntity sendEmailAttachment(@PathVariable(\"user-email\") String email) {          try {             emailService.sendEmailWithAttachment(email, \"Order Confirmation\", \"Thanks for your recent order\",                     \"classpath:purchase_order.pdf\");         } catch (MessagingException | FileNotFoundException mailException) {             LOG.error(\"Error while sending out email..{}\", mailException.getStackTrace());             return new ResponseEntity&lt;&gt;(\"Unable to send email\", HttpStatus.INTERNAL_SERVER_ERROR);         }          return new ResponseEntity&lt;&gt;(\"Please check your inbox for order confirmation\", HttpStatus.OK);     }  }<\/code><\/pre>\n<h3>5. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 Spring&nbsp;Boot<\/h3>\n<pre><code class=\"java\">@SpringBootApplication public class SendEmailUsingSpringApplication {     public static void main(String[] args) {       SpringApplication.run(SendEmailUsingSpringApplication.class, args);    }  }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0430\u043c:<\/p>\n<pre><code>http:\/\/localhost:8080\/email\/order-email\/umeshawasthi@www.javadevjournal.com http:\/\/localhost:8080\/email\/simple-email\/umeshawasthi@www.javadevjournal.com<\/code><\/pre>\n<h3>6. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 Gmail<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SMTP-\u0441\u0435\u0440\u0432\u0435\u0440 Gmail, \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441\u043e <a href=\"https:\/\/support.google.com\/accounts\/answer\/185833\"><u>\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439<\/u><\/a> \u0441\u0442\u0430\u0442\u044c\u0435\u0439. \u0418\u0437-\u0437\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0440 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432 Gmail \u0432\u0430\u0448 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u043e\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.&nbsp;<\/p>\n<h3>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring&nbsp;Boot \u0438 Thymeleaf<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring&nbsp;Boot \u0438 Thymeleaf.<\/p>\n<p>Thyleleaf&nbsp;\u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440. Thymeleaf \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HTML \u0441 \u0448\u0438\u0440\u043e\u043a\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0443\u0447\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<h3>7. \u041a\u043b\u0430\u0441\u0441 EmailContext<\/h3>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>EmailContext<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u0441\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b. \u041d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">public abstract class AbstractEmailContext {      private String from;     private String to;     private String subject;     private String email;     private String attachment;     private String fromDisplayName;     private String emailLanguage;     private String displayName;     private String templateLocation;     private Map &lt;String, Object&gt; context;     \/\/getter and seter methods }<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<ul>\n<li>\n<p><code>templateLocation<\/code>&nbsp;\u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p><code>context<\/code>&nbsp;\u2014 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u043c \u043f\u0438\u0441\u044c\u043c\u0435. Thymeleaf \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043a\u0430\u0440\u0442\u0443 \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0430\u0448\u0435 \u0438\u043c\u044f \u0438 \u0442.&nbsp;\u0434.).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u043b\u0443\u0436\u0431\u0443 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 Thymeleaf \u0434\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c.<\/p>\n<h3>8. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f EmailService<\/h3>\n<pre><code class=\"java\">package com.javadevjournal.core.email.service;      import com.javadevjournal.core.email.context.AbstractEmailContext;     import org.springframework.beans.factory.annotation.Autowired;     import org.springframework.mail.javamail.JavaMailSender;     import org.springframework.mail.javamail.MimeMessageHelper;     import org.springframework.stereotype.Service;     import org.thymeleaf.context.Context;     import org.thymeleaf.spring5.SpringTemplateEngine;          import javax.mail.MessagingException;     import javax.mail.internet.MimeMessage;     import java.nio.charset.StandardCharsets;          @Service     public class DefaultEmailService implements EmailService {              @Autowired         private JavaMailSender emailSender;              @Autowired         private SpringTemplateEngine templateEngine;              @Override         public void sendMail(AbstractEmailContext email) throws MessagingException {             MimeMessage message = emailSender.createMimeMessage();             MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(message,                 MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,                 StandardCharsets.UTF_8.name());             Context context = new Context();             context.setVariables(email.getContext());             String emailContent = templateEngine.process(email.getTemplateLocation(), context);                  mimeMessageHelper.setTo(email.getTo());             mimeMessageHelper.setSubject(email.getSubject());             mimeMessageHelper.setFrom(email.getFrom());             mimeMessageHelper.setText(emailContent, true);             emailSender.send(message);         }     }<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<ol>\n<li>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0443 \u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. <code>Thymeleaf<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0435\u0439 \u0438\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p><code>SpringTemplateEngine<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432, \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <code>Thymeleaf<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>templateEngine.process()<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. \u041e\u043d\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d HTML, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 <code>MimeMessage<\/code> \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a HTML (<code>mimeMessageHelper.setText(emailContent, true)<\/code>)<\/p>\n<\/li>\n<\/ol>\n<h3>9. \u0428\u0430\u0431\u043b\u043e\u043d \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u044c\u043c\u0430<\/h3>\n<p>\u0412\u043e\u0442 \u043d\u0430\u0448 HTML-\u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u044c\u043c\u0430 (\u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043c\u0435\u0441\u0442\u0430 \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b HTML-\u043a\u043e\u0434).<\/p>\n<pre><code class=\"java\">&lt;!DOCTYPE html&gt;     &lt;html lang=\"en\" xmlns:th=\"http:\/\/www.thymeleaf.org\" xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\"&gt;     &lt;head&gt;         &lt;meta charset=\"utf-8\"&gt; &lt;!-- utf-8 works for most cases --&gt;         &lt;meta name=\"viewport\" content=\"width=device-width\"&gt; &lt;!-- Forcing initial-scale shouldn't be necessary --&gt;         &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"&gt; &lt;!-- Use the latest (edge) version of IE rendering engine --&gt;         &lt;meta name=\"x-apple-disable-message-reformatting\"&gt;  &lt;!-- Disable auto-scale in iOS 10 Mail entirely --&gt;         &lt;title&gt;&lt;\/title&gt; &lt;!-- The title tag shows in email notifications, like Android 4.4. --&gt;              &lt;link href=\"https:\/\/fonts.googleapis.com\/css?family=Lato:300,400,700\" rel=\"stylesheet\"&gt;              &lt;!-- CSS Reset : BEGIN --&gt;      &lt;\/head&gt;          &lt;body width=\"100%\" style=\"margin: 0; padding: 0 !important; mso-line-height-rule: exactly; background-color: #f1f1f1;\"&gt;     &lt;center style=\"width: 100%; background-color: #f1f1f1;\"&gt;         &lt;div style=\"display: none; font-size: 1px;max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-family: sans-serif;\"&gt;             &amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;&amp;zwnj;&amp;nbsp;         &lt;\/div&gt;         &lt;div style=\"max-width: 600px; margin: 0 auto;\" class=\"email-container\"&gt;             &lt;!-- BEGIN BODY --&gt;             &lt;table align=\"center\" role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\" style=\"margin: auto;\"&gt;                 &lt;tr&gt;                     &lt;td valign=\"top\" class=\"bg_white\" style=\"padding: 1em 2.5em 0 2.5em;\"&gt;                         &lt;table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"&gt;                             &lt;tr&gt;                                 &lt;td class=\"logo\" style=\"text-align: center;\"&gt;                                     &lt;h1&gt;Welcome&lt;\/h1&gt;                                 &lt;\/td&gt;                             &lt;\/tr&gt;                         &lt;\/table&gt;                     &lt;\/td&gt;                 &lt;\/tr&gt;&lt;!-- end tr --&gt;                 &lt;tr&gt;                     &lt;td valign=\"middle\" class=\"hero bg_white\" style=\"padding: 2em 0 4em 0;\"&gt;                         &lt;table&gt;                             &lt;tr&gt;                                 &lt;td&gt;                                     &lt;div class=\"text\" style=\"padding: 0 2.5em; text-align: center;\"&gt;                                         &lt;h2&gt;Finish creating your account.&lt;\/h2&gt;                                         &lt;h3&gt;Hi&lt;p th:text=\"${firstName}\"&gt;&lt;\/h3&gt;                                         &lt;h3&gt;We're excited to have you get started. First, you need to confirm your account. Just press the button below.&lt;\/h3&gt;                                         &lt;p&gt;&lt;a th:href=\"${verificationURL}\" class=\"btn btn-primary\"&gt;Validate Account&lt;\/a&gt;&lt;\/p&gt;                                     &lt;\/div&gt;                                 &lt;\/td&gt;                             &lt;\/tr&gt;                             &lt;tr&gt;                                 &lt;td&gt;                                     &lt;div class=\"text\" style=\"padding: 0 2.5em; text-align: center;\"&gt;                                         &lt;h3&gt;if you experience any issues with the button above, copy and paste the URL below into your web browser.&lt;\/h3&gt;                                         &lt;p th:text=\"${verificationURL}\"&gt;&lt;\/p&gt;                                     &lt;\/div&gt;                                 &lt;\/td&gt;                             &lt;\/tr&gt;                         &lt;\/table&gt;                     &lt;\/td&gt;                 &lt;\/tr&gt;&lt;!-- end tr --&gt;                 &lt;!-- 1 Column Text + Button : END --&gt;             &lt;\/table&gt;             &lt;table align=\"center\" role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\" style=\"margin: auto;\"&gt;                 &lt;tr&gt;                     &lt;td valign=\"middle\" class=\"bg_light footer email-section\"&gt;                         &lt;table&gt;                             &lt;tr&gt;                                 &lt;td valign=\"top\" width=\"33.333%\" style=\"padding-top: 20px;\"&gt;                                     &lt;table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"&gt;                                         &lt;tr&gt;                                             &lt;td style=\"text-align: left; padding-right: 10px;\"&gt;                                                 &lt;h3 class=\"heading\"&gt;About&lt;\/h3&gt;                                                 &lt;p&gt;Welcome to Java Development Journal Blog. We publish articles on                                                     Spring, Spring Boot and Spring Security.                                                 &lt;\/p&gt;                                             &lt;\/td&gt;                                         &lt;\/tr&gt;                                     &lt;\/table&gt;                                 &lt;\/td&gt;                                 &lt;td valign=\"top\" width=\"33.333%\" style=\"padding-top: 20px;\"&gt;                                     &lt;table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"&gt;                                         &lt;tr&gt;                                             &lt;td style=\"text-align: left; padding-left: 5px; padding-right: 5px;\"&gt;                                                 &lt;h3 class=\"heading\"&gt;Contact Info&lt;\/h3&gt;                                                 &lt;ul&gt;                                                     &lt;li&gt;&lt;span class=\"text\"&gt;Java Development Journal&lt;\/span&gt;&lt;\/li&gt;                                                 &lt;\/ul&gt;                                             &lt;\/td&gt;                                         &lt;\/tr&gt;                                     &lt;\/table&gt;                                 &lt;\/td&gt;                                 &lt;td valign=\"top\" width=\"33.333%\" style=\"padding-top: 20px;\"&gt;                                     &lt;table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"&gt;                                         &lt;tr&gt;                                             &lt;td style=\"text-align: left; padding-left: 10px;\"&gt;                                                 &lt;h3 class=\"heading\"&gt;Useful Links&lt;\/h3&gt;                                                 &lt;ul&gt;                                                     &lt;li&gt;&lt;a href=\"#\"&gt;Home&lt;\/a&gt;&lt;\/li&gt;                                                     &lt;li&gt;&lt;a href=\"#\"&gt;About&lt;\/a&gt;&lt;\/li&gt;                                                 &lt;\/ul&gt;                                             &lt;\/td&gt;                                         &lt;\/tr&gt;                                     &lt;\/table&gt;                                 &lt;\/td&gt;                             &lt;\/tr&gt;                         &lt;\/table&gt;                     &lt;\/td&gt;                 &lt;\/tr&gt;&lt;!-- end: tr --&gt;             &lt;\/table&gt;              &lt;\/div&gt;     &lt;\/center&gt;     &lt;\/body&gt;     &lt;\/html&gt;<\/code><\/pre>\n<p>\u0418\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f <code>${firstName}<\/code> \u0438 <code>${verifyURL}<\/code>, \u0447\u0442\u043e\u0431\u044b <code>Thymeleaf<\/code> \u043c\u043e\u0433 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<h4>\u0420\u0435\u0437\u044e\u043c\u0435<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring. \u041c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Spring&nbsp;Boot. \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435, \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/github.com\/umeshawasthi\/javadevjournal\/tree\/master\/Spring-Boot\/spring-email\"><u>GitHub<\/u><\/a>.<\/p>\n<hr>\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/NlV9\/\"><strong>\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 Spring Framework\u00bb.<\/strong><\/a><\/p>\n<p>\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0442\u0430\u043a\u0436\u0435 \u0432\u0441\u0435\u0445 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0432\u0435\u0431\u0438\u043d\u0430\u0440 <a href=\"https:\/\/otus.pw\/JxyD\/\"><strong>\u00abSpring \u0432 Docker. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b\u00bb<\/strong><\/a>. \u041d\u0430 \u0437\u0430\u043d\u044f\u0442\u0438\u0438 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0443\u044e \u0442\u0435\u043c\u0443 \u043f\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0443 Spring-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432 Docker-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0438 \u043d\u0435 \u0432\u0441\u0435\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u0437\u0430\u0434\u0430\u0447.  <\/p>\n<\/blockquote>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/557798\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/557798\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<hr>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 <a href=\"https:\/\/www.javadevjournal.com\/spring-boot\/\"><u>\u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0441\u0435\u0440\u0438\u0438 \u043f\u043e Spring&nbsp;Boot<\/u><\/a> \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring.<\/p>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c&nbsp;\u2014 \u043e\u0434\u043d\u0430 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0418\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring. \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0432\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SMTP \u0434\u043b\u044f Gmail (\u0438\u043c\u0435\u0439\u0442\u0435 \u0432 \u0432\u0438\u0434\u0443, \u0447\u0442\u043e \u0443 Gmail \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b). \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 JavaMailSender \u0432 Spring&nbsp;Framework \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, \u0430 <a href=\"https:\/\/www.javadevjournal.com\/spring\/spring-boot-auto-configuration\/\"><u>Spring&nbsp;Boot \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443<\/u><\/a> \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438 \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f.<\/p>\n<h3>1. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 Maven<\/h3>\n<p>\u0427\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 Spring Boot \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 spring-boot-starter-mail \u0432 \u0444\u0430\u0439\u043b pom.xml. \u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>pom.xml<\/code>:<\/p>\n<pre><code class=\"java\">&lt;dependency&gt; \t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt; \t&lt;artifactId&gt;spring-boot-starter-mail&lt;\/artifactId&gt; &lt;\/dependency&gt;<\/code><\/pre>\n<h3>2. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b<\/h3>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0447\u0442\u044b \u0434\u043b\u044f <em>\u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring&nbsp;Boot<\/em>:<\/p>\n<pre><code class=\"java\">spring.mail.host=smtp.gmail.com spring.mail.port=587 spring.mail.username= gmail user name spring.mail.password= your password spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0443 Gmail. \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u0438\u0445 \u0441\u0432\u043e\u0438\u043c\u0438<\/p>\n<h3>3. \u0421\u043b\u0443\u0436\u0431\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b<\/h3>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043b\u0443\u0436\u0431\u044b \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u0447\u0442\u043e\u0432\u043e\u0439 \u0441\u043b\u0443\u0436\u0431\u044b \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<ol>\n<li>\n<p>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u0430\u0448 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">@Service public class DefaultEmailService implements EmailService {   @Autowired  public JavaMailSender emailSender;   @Override  public void sendSimpleEmail(String toAddress, String subject, String message) {    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();   simpleMailMessage.setTo(toAddress);   simpleMailMessage.setSubject(subject);   simpleMailMessage.setText(message);   emailSender.send(simpleMailMessage);  }   @Override  public void sendEmailWithAttachment(String toAddress, String subject, String message, String attachment) throws MessagingException, FileNotFoundException {    MimeMessage mimeMessage = emailSender.createMimeMessage();   MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);   messageHelper.setTo(toAddress);   messageHelper.setSubject(subject);   messageHelper.setText(message);   FileSystemResource file = new FileSystemResource(ResourceUtils.getFile(attachment));   messageHelper.addAttachment(\"Purchase Order\", file);   emailSender.send(mimeMessage);  } }<\/code><\/pre>\n<h3>4. \u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h3>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 REST, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u0434. \u0423 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 REST \u0431\u0443\u0434\u0435\u0442 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430. \u0421\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">package com.javadevjournal.controller;  import com.javadevjournal.email.service.EmailService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.mail.MailException; import org.springframework.web.bind.annotation.*;  import javax.mail.MessagingException; import java.io.FileNotFoundException;  @RestController @RequestMapping(\"\/email\") public class EmailController {      private static final Logger LOG = LoggerFactory.getLogger(EmailController.class);      @Autowired     EmailService emailService;      @GetMapping(value = \"\/simple-email\/{user-email}\")     public @ResponseBody ResponseEntity sendSimpleEmail(@PathVariable(\"user-email\") String email) {          try {             emailService.sendSimpleEmail(email, \"Welcome\", \"This is a welcome email for your!!\");         } catch (MailException mailException) {             LOG.error(\"Error while sending out email..{}\", mailException.getStackTrace());             return new ResponseEntity&lt;&gt;(\"Unable to send email\", HttpStatus.INTERNAL_SERVER_ERROR);         }          return new ResponseEntity&lt;&gt;(\"Please check your inbox\", HttpStatus.OK);     }      @GetMapping(value = \"\/simple-order-email\/{user-email}\")     public @ResponseBody ResponseEntity sendEmailAttachment(@PathVariable(\"user-email\") String email) {          try {             emailService.sendEmailWithAttachment(email, \"Order Confirmation\", \"Thanks for your recent order\",                     \"classpath:purchase_order.pdf\");         } catch (MessagingException | FileNotFoundException mailException) {             LOG.error(\"Error while sending out email..{}\", mailException.getStackTrace());             return new ResponseEntity&lt;&gt;(\"Unable to send email\", HttpStatus.INTERNAL_SERVER_ERROR);         }          return new ResponseEntity&lt;&gt;(\"Please check your inbox for order confirmation\", HttpStatus.OK);     }  }<\/code><\/pre>\n<h3>5. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 Spring&nbsp;Boot<\/h3>\n<pre><code class=\"java\">@SpringBootApplication public class SendEmailUsingSpringApplication {     public static void main(String[] args) {       SpringApplication.run(SendEmailUsingSpringApplication.class, args);    }  }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0430\u043c:<\/p>\n<pre><code>http:\/\/localhost:8080\/email\/order-email\/umeshawasthi@www.javadevjournal.com http:\/\/localhost:8080\/email\/simple-email\/umeshawasthi@www.javadevjournal.com<\/code><\/pre>\n<h3>6. \u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f SMTP-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 Gmail<\/h3>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c SMTP-\u0441\u0435\u0440\u0432\u0435\u0440 Gmail, \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u044c\u0442\u0435\u0441\u044c \u0441\u043e <a href=\"https:\/\/support.google.com\/accounts\/answer\/185833\"><u>\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439<\/u><\/a> \u0441\u0442\u0430\u0442\u044c\u0435\u0439. \u0418\u0437-\u0437\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0440 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432 Gmail \u0432\u0430\u0448 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0430\u0440\u043e\u043b\u044c \u043e\u0442 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.&nbsp;<\/p>\n<h3>\u041e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring&nbsp;Boot \u0438 Thymeleaf<\/h3>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Spring&nbsp;Boot \u0438 Thymeleaf.<\/p>\n<p>Thyleleaf&nbsp;\u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440. Thymeleaf \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0435 \u043f\u0438\u0441\u044c\u043c\u0430 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HTML \u0441 \u0448\u0438\u0440\u043e\u043a\u0438\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u0438\u0435\u043d\u0442\u0443 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0435 \u043f\u0438\u0441\u044c\u043c\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0443\u0447\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438.<\/p>\n<h3>7. \u041a\u043b\u0430\u0441\u0441 EmailContext<\/h3>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 <code>EmailContext<\/code>, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432\u0441\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 \u0434\u043b\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b. \u041d\u0430\u0448 \u043a\u043b\u0430\u0441\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">public abstract class AbstractEmailContext {      private String from;     private String to;     private String subject;     private String email;     private String attachment;     private String fromDisplayName;     private String emailLanguage;     private String displayName;     private String templateLocation;     private Map &lt;String, Object&gt; context;     \/\/getter and seter methods }<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<ul>\n<li>\n<p><code>templateLocation<\/code>&nbsp;\u2014 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u0430. \u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043d\u0430\u043c \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0432\u043e\u0434\u0430.<\/p>\n<\/li>\n<li>\n<p><code>context<\/code>&nbsp;\u2014 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u043c \u043f\u0438\u0441\u044c\u043c\u0435. Thymeleaf \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043a\u0430\u0440\u0442\u0443 \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0430\u0448\u0435 \u0438\u043c\u044f \u0438 \u0442.&nbsp;\u0434.).<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043d\u0430\u0448\u0443 \u0441\u043b\u0443\u0436\u0431\u0443 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0439 \u043f\u043e\u0447\u0442\u044b \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 HTML-\u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 Thymeleaf \u0434\u043b\u044f \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u044b\u0445 \u043f\u0438\u0441\u0435\u043c.<\/p>\n<h3>8. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f EmailService<\/h3>\n<pre><code class=\"java\">package com.javadevjournal.core.email.service;      import com.javadevjournal.core.email.context.AbstractEmailContext;     import org.springframework.beans.factory.annotation.Autowired;     import org.springframework.mail.javamail.JavaMailSender;     import org.springframework.mail.javamail.MimeMessageHelper;     import org.springframework.stereotype.Service;     import org.thymeleaf.context.Context;     import org.thymeleaf.spring5.SpringTemplateEngine;          import javax.mail.MessagingException;     import javax.mail.internet.MimeMessage;     import java.nio.charset.StandardCharsets;          @Service     public class DefaultEmailService implements EmailService {              @Autowired         private JavaMailSender emailSender;              @Autowired         private SpringTemplateEngine templateEngine;              @Override         public void sendMail(AbstractEmailContext email) throws MessagingException {             MimeMessage message = emailSender.createMimeMessage();             MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(message,                 MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,                 StandardCharsets.UTF_8.name());             Context context = new Context();             context.setVariables(email.getContext());             String emailContent = templateEngine.process(email.getTemplateLocation(), context);                  mimeMessageHelper.setTo(email.getTo());             mimeMessageHelper.setSubject(email.getSubject());             mimeMessageHelper.setFrom(email.getFrom());             mimeMessageHelper.setText(emailContent, true);             emailSender.send(message);         }     }<\/code><\/pre>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0432\u044b\u0448\u0435 \u043a\u043e\u0434\u0435 \u0435\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0436\u043d\u044b\u0445 \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<ol>\n<li>\n<p>\u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0443 \u043a\u0430\u043a \u043d\u0430\u0431\u043e\u0440 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. <code>Thymeleaf<\/code> \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0434\u043b\u044f \u0437\u0430\u043c\u0435\u043d\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0435\u0439 \u0438\u043b\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<\/li>\n<li>\n<p><code>SpringTemplateEngine<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432, \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u043e\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0438\u0437\u0430\u0442\u043e\u0440\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <code>Thymeleaf<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>templateEngine.process()<\/code> \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438. \u041e\u043d\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0448\u0430\u0431\u043b\u043e\u043d HTML, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0435\u0433\u043e \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0432\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 <code>MimeMessage<\/code> \u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a HTML (<code>mimeMessageHelper.setText(emailContent, true)<\/code>)<\/p>\n<\/li>\n<\/ol>\n<h3>9. \u0428\u0430\u0431\u043b\u043e\u043d \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u044c\u043c\u0430<\/h3>\n<p>\u0412\u043e\u0442 \u043d\u0430\u0448 HTML-\u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u044c\u043c\u0430 (\u0434\u043b\u044f \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0438 \u043c\u0435\u0441\u0442\u0430 \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b HTML-\u043a\u043e\u0434).<\/p>\n<pre><code class=\"java\">&lt;!DOCTYPE html&gt;     &lt;html lang=\"en\" xmlns:th=\"http:\/\/www.thymeleaf.org\" xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"<\/code><\/pre>\n<\/hr>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-323249","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=323249"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/323249\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}