| | 1 | | namespace Syki.Back.Emails; |
| | 2 | |
|
| | 3 | | public class EmailsService : IEmailsService |
| | 4 | | { |
| | 5 | | private readonly HttpClient _client; |
| | 6 | | private readonly EmailSettings _settings; |
| 0 | 7 | | public EmailsService(EmailSettings settings) |
| | 8 | | { |
| 0 | 9 | | _settings = settings; |
| 0 | 10 | | _client = new HttpClient { BaseAddress = new Uri(settings.ApiUrl) }; |
| 0 | 11 | | _client.DefaultRequestHeaders.Add("api-key", settings.ApiKey); |
| 0 | 12 | | } |
| | 13 | |
|
| | 14 | | public async Task SendResetPasswordEmail(string to, string token) |
| | 15 | | { |
| 0 | 16 | | if (to.Contains("@syki")) return; |
| | 17 | |
|
| 0 | 18 | | var link = $"{_settings.FrontUrl}/reset-password?token={token}"; |
| 0 | 19 | | var body = new BrevoEmailMessage( |
| 0 | 20 | | sender: "syki@zaqbit.com", |
| 0 | 21 | | to: to, |
| 0 | 22 | | subject: "Syki - Redefinição de senha", |
| 0 | 23 | | content: GetContent("Redefinição de senha", "Para redefinir sua senha, clique no botão abaixo e siga as inst |
| 0 | 24 | | ); |
| | 25 | |
|
| 0 | 26 | | await _client.PostAsJsonAsync("", body); |
| 0 | 27 | | } |
| | 28 | |
|
| | 29 | | public async Task SendUserRegisterEmailConfirmation(string to, string token) |
| | 30 | | { |
| 0 | 31 | | if (to.Contains("@syki")) return; |
| | 32 | |
|
| 0 | 33 | | var link = $"{_settings.FrontUrl}/register-setup?token={token}"; |
| 0 | 34 | | var body = new BrevoEmailMessage( |
| 0 | 35 | | sender: "syki@zaqbit.com", |
| 0 | 36 | | to: to, |
| 0 | 37 | | subject: "Syki - Cadastro", |
| 0 | 38 | | content: GetContent("Cadastro", "Para finalizar seu cadastro, clique no botão abaixo e siga as instruções.", |
| 0 | 39 | | ); |
| | 40 | |
|
| 0 | 41 | | await _client.PostAsJsonAsync("", body); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | public async Task SendNewClassActivityEmail(string to, string message) |
| | 45 | | { |
| 0 | 46 | | if (to.Contains("@syki")) return; |
| | 47 | |
|
| 0 | 48 | | var body = new BrevoEmailMessage( |
| 0 | 49 | | sender: "syki@zaqbit.com", |
| 0 | 50 | | to: to, |
| 0 | 51 | | subject: "Syki - Nova atividade", |
| 0 | 52 | | content: message |
| 0 | 53 | | ); |
| | 54 | |
|
| 0 | 55 | | await _client.PostAsJsonAsync("", body); |
| 0 | 56 | | } |
| | 57 | |
|
| | 58 | | private static string GetContent(string title, string description, string button, string link) |
| | 59 | | { |
| 0 | 60 | | return """ |
| 0 | 61 | | <!doctype html> |
| 0 | 62 | | <html lang="pt-BR"> |
| 0 | 63 | | <head> |
| 0 | 64 | | <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> |
| 0 | 65 | | </head> |
| 0 | 66 | | <body marginheight="0" topmargin="0" marginwidth="0" style="margin: 0px; background-color: #f2f3f8;" leftmargin="0 |
| 0 | 67 | | <table cellspacing="0" border="0" cellpadding="0" width="100%" bgcolor="#f2f3f8" |
| 0 | 68 | | style="@import url(https://fonts.googleapis.com/css?family=Rubik:300,400,500,700|Open+Sans:300,400,600,700); f |
| 0 | 69 | | <tr> |
| 0 | 70 | | <td> |
| 0 | 71 | | <table style="background-color: #f2f3f8; max-width:670px; margin:0 auto;" width="100%" border="0" align=" |
| 0 | 72 | | <tr> |
| 0 | 73 | | <td style="height:80px;"> </td> |
| 0 | 74 | | </tr> |
| 0 | 75 | | <tr> |
| 0 | 76 | | <td> |
| 0 | 77 | | <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" |
| 0 | 78 | | style="max-width:670px;background:#fff; border-radius:3px; text-align:center;-webkit-box-shadow:0 |
| 0 | 79 | | <tr> |
| 0 | 80 | | <td style="height:40px;"> </td> |
| 0 | 81 | | </tr> |
| 0 | 82 | | <tr> |
| 0 | 83 | | <td style="padding:0 35px;"> |
| 0 | 84 | | <h1 style="color:#1e1e2d; font-weight:500; margin:0;font-size:32px;font-family:'Rubik',sans-se |
| 0 | 85 | | SykiTitle</h1> |
| 0 | 86 | | <span |
| 0 | 87 | | style="display:inline-block; vertical-align:middle; margin:29px 0 26px; border-bottom:1px so |
| 0 | 88 | | <p style="color:#455056; font-size:15px;line-height:24px; margin:0;"> |
| 0 | 89 | | SykiDescription |
| 0 | 90 | | </p> |
| 0 | 91 | | <a href="SykiFrontendLink" |
| 0 | 92 | | style="background:#4caf50;text-decoration:none !important; font-weight:500; margin-top:35px; |
| 0 | 93 | | SykiButton |
| 0 | 94 | | </a> |
| 0 | 95 | | </td> |
| 0 | 96 | | </tr> |
| 0 | 97 | | <tr> |
| 0 | 98 | | <td style="height:40px;"> </td> |
| 0 | 99 | | </tr> |
| 0 | 100 | | </table> |
| 0 | 101 | | </td> |
| 0 | 102 | | </tr> |
| 0 | 103 | | <tr> |
| 0 | 104 | | <td style="height:80px;"> </td> |
| 0 | 105 | | </tr> |
| 0 | 106 | | </table> |
| 0 | 107 | | </td> |
| 0 | 108 | | </tr> |
| 0 | 109 | | </table> |
| 0 | 110 | | </body> |
| 0 | 111 | | </html> |
| 0 | 112 | | """ |
| 0 | 113 | | .Replace("SykiTitle", title) |
| 0 | 114 | | .Replace("SykiDescription", description) |
| 0 | 115 | | .Replace("SykiButton", button) |
| 0 | 116 | | .Replace("SykiFrontendLink", link); |
| | 117 | | } |
| | 118 | | } |