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