[74af394] | 1 | package com.example.salonbella.service.mail;
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | import lombok.AllArgsConstructor;
|
---|
| 5 | import org.springframework.mail.javamail.JavaMailSender;
|
---|
| 6 | import org.springframework.mail.javamail.MimeMessageHelper;
|
---|
| 7 | import org.springframework.stereotype.Service;
|
---|
| 8 |
|
---|
| 9 | import javax.mail.internet.MimeMessage;
|
---|
| 10 |
|
---|
| 11 | @AllArgsConstructor
|
---|
| 12 | @Service
|
---|
| 13 | public class EmailService {
|
---|
| 14 |
|
---|
| 15 | private JavaMailSender javaMailSender;
|
---|
| 16 |
|
---|
| 17 | public void send(String to, String name, String token) {
|
---|
| 18 | MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
---|
| 19 | try {
|
---|
| 20 |
|
---|
| 21 | MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false,"utf-8");
|
---|
| 22 | helper.setText(buildEmail(name, "http://localhost:8080/confirm?token=" + token), true);
|
---|
| 23 | helper.setTo(to);
|
---|
| 24 | helper.setSubject("Confirm your account");
|
---|
| 25 | helper.setFrom("salonbella@gmail.com");
|
---|
| 26 | javaMailSender.send(mimeMessage);
|
---|
| 27 | } catch (Exception ignored) {
|
---|
| 28 |
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | private String buildEmail(String name, String link) {
|
---|
| 34 | return "<div style=\"font-family:Helvetica,Arial,sans-serif;font-size:16px;margin:0;color:#0b0c0c\">\n" +
|
---|
| 35 | "\n" +
|
---|
| 36 | "<span style=\"display:none;font-size:1px;color:#fff;max-height:0\"></span>\n" +
|
---|
| 37 | "\n" +
|
---|
| 38 | " <table role=\"presentation\" width=\"100%\" style=\"border-collapse:collapse;min-width:100%;width:100%!important\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n" +
|
---|
| 39 | " <tbody><tr>\n" +
|
---|
| 40 | " <td width=\"100%\" height=\"53\" bgcolor=\"#0b0c0c\">\n" +
|
---|
| 41 | " \n" +
|
---|
| 42 | " <table role=\"presentation\" width=\"100%\" style=\"border-collapse:collapse;max-width:580px\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\">\n" +
|
---|
| 43 | " <tbody><tr>\n" +
|
---|
| 44 | " <td width=\"70\" bgcolor=\"#0b0c0c\" valign=\"middle\">\n" +
|
---|
| 45 | " <table role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse\">\n" +
|
---|
| 46 | " <tbody><tr>\n" +
|
---|
| 47 | " <td style=\"padding-left:10px\">\n" +
|
---|
| 48 | " \n" +
|
---|
| 49 | " </td>\n" +
|
---|
| 50 | " <td style=\"font-size:28px;line-height:1.315789474;Margin-top:4px;padding-left:10px\">\n" +
|
---|
| 51 | " <span style=\"font-family:Helvetica,Arial,sans-serif;font-weight:700;color:#ffffff;text-decoration:none;vertical-align:top;display:inline-block\">Confirm your email</span>\n" +
|
---|
| 52 | " </td>\n" +
|
---|
| 53 | " </tr>\n" +
|
---|
| 54 | " </tbody></table>\n" +
|
---|
| 55 | " </a>\n" +
|
---|
| 56 | " </td>\n" +
|
---|
| 57 | " </tr>\n" +
|
---|
| 58 | " </tbody></table>\n" +
|
---|
| 59 | " \n" +
|
---|
| 60 | " </td>\n" +
|
---|
| 61 | " </tr>\n" +
|
---|
| 62 | " </tbody></table>\n" +
|
---|
| 63 | " <table role=\"presentation\" class=\"m_-6186904992287805515content\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse;max-width:580px;width:100%!important\" width=\"100%\">\n" +
|
---|
| 64 | " <tbody><tr>\n" +
|
---|
| 65 | " <td width=\"10\" height=\"10\" valign=\"middle\"></td>\n" +
|
---|
| 66 | " <td>\n" +
|
---|
| 67 | " \n" +
|
---|
| 68 | " <table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse\">\n" +
|
---|
| 69 | " <tbody><tr>\n" +
|
---|
| 70 | " <td bgcolor=\"#1D70B8\" width=\"100%\" height=\"10\"></td>\n" +
|
---|
| 71 | " </tr>\n" +
|
---|
| 72 | " </tbody></table>\n" +
|
---|
| 73 | " \n" +
|
---|
| 74 | " </td>\n" +
|
---|
| 75 | " <td width=\"10\" valign=\"middle\" height=\"10\"></td>\n" +
|
---|
| 76 | " </tr>\n" +
|
---|
| 77 | " </tbody></table>\n" +
|
---|
| 78 | "\n" +
|
---|
| 79 | "\n" +
|
---|
| 80 | "\n" +
|
---|
| 81 | " <table role=\"presentation\" class=\"m_-6186904992287805515content\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-collapse:collapse;max-width:580px;width:100%!important\" width=\"100%\">\n" +
|
---|
| 82 | " <tbody><tr>\n" +
|
---|
| 83 | " <td height=\"30\"><br></td>\n" +
|
---|
| 84 | " </tr>\n" +
|
---|
| 85 | " <tr>\n" +
|
---|
| 86 | " <td width=\"10\" valign=\"middle\"><br></td>\n" +
|
---|
| 87 | " <td style=\"font-family:Helvetica,Arial,sans-serif;font-size:19px;line-height:1.315789474;max-width:560px\">\n" +
|
---|
| 88 | " \n" +
|
---|
| 89 | " <p style=\"Margin:0 0 20px 0;font-size:19px;line-height:25px;color:#0b0c0c\">Hi " + name + ",</p><p style=\"Margin:0 0 20px 0;font-size:19px;line-height:25px;color:#0b0c0c\"> Thank you for registering. Please click on the below link to activate your account: </p><blockquote style=\"Margin:0 0 20px 0;border-left:10px solid #b1b4b6;padding:15px 0 0.1px 15px;font-size:19px;line-height:25px\"><p style=\"Margin:0 0 20px 0;font-size:19px;line-height:25px;color:#0b0c0c\"> <a href=\"" + link + "\">Activate Now</a> </p></blockquote>\n Link will expire in 30 minutes. <p>See you soon</p>" +
|
---|
| 90 | " \n" +
|
---|
| 91 | " </td>\n" +
|
---|
| 92 | " <td width=\"10\" valign=\"middle\"><br></td>\n" +
|
---|
| 93 | " </tr>\n" +
|
---|
| 94 | " <tr>\n" +
|
---|
| 95 | " <td height=\"30\"><br></td>\n" +
|
---|
| 96 | " </tr>\n" +
|
---|
| 97 | " </tbody></table><div class=\"yj6qo\"></div><div class=\"adL\">\n" +
|
---|
| 98 | "\n" +
|
---|
| 99 | "</div></div>";
|
---|
| 100 | }
|
---|
| 101 | }
|
---|