| | | 1 | | using ArturRios.Heimdall.Command.Services; |
| | | 2 | | using ArturRios.Messaging.Email; |
| | | 3 | | |
| | | 4 | | namespace ArturRios.Heimdall.WebApi.Email; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Delivers UC-06's verification token as a real email through Mailgun (FR-EV-01/02), replacing |
| | | 8 | | /// the <see cref="LoggingEmailVerificationSender" /> stub that use case shipped with. Registered |
| | | 9 | | /// whenever Mailgun is configured. |
| | | 10 | | /// </summary> |
| | | 11 | | public class MailgunEmailVerificationSender( |
| | | 12 | | IEmailService emailService, |
| | | 13 | | EmailDeliveryOptions options, |
| | | 14 | | ILogger<MailgunEmailVerificationSender> logger) |
| | 6 | 15 | | : MailgunSender(emailService, logger), IEmailVerificationSender |
| | | 16 | | { |
| | | 17 | | private const string Subject = "Verify your email address"; |
| | | 18 | | |
| | 6 | 19 | | protected override string Purpose => "email verification"; |
| | | 20 | | |
| | | 21 | | public Task SendAsync(string email, string token, string? linkBase) |
| | | 22 | | { |
| | | 23 | | // The scope's own link wins; without one the deployment-wide setting applies. |
| | 6 | 24 | | var link = EmailDeliveryOptions.BuildLink( |
| | 6 | 25 | | string.IsNullOrWhiteSpace(linkBase) ? options.VerificationUrl : linkBase, token); |
| | | 26 | | |
| | 6 | 27 | | var body = string.IsNullOrEmpty(link) |
| | 6 | 28 | | ? $""" |
| | 6 | 29 | | Welcome! Confirm this address to finish setting up your account. |
| | 6 | 30 | | |
| | 6 | 31 | | Use this token to verify it: {token} |
| | 6 | 32 | | """ |
| | 6 | 33 | | : $""" |
| | 6 | 34 | | Welcome! Confirm this address to finish setting up your account. |
| | 6 | 35 | | |
| | 6 | 36 | | Verify it here: {link} |
| | 6 | 37 | | """; |
| | | 38 | | |
| | 6 | 39 | | return DeliverAsync(email, Subject, body); |
| | | 40 | | } |
| | | 41 | | } |