public async Task <string> Enqueue <TData>(MailTemplateData mailData, Type template, TData data) { try { return(await _backgroundJobService.Enqueue(() => Send(mailData, template, data))); } catch (Exception) // Fallback { await Send(mailData, template, data); } return(""); }
public async Task Handle(DomainEventNotification <UserRegistered> notification, CancellationToken cancellationToken) { var user = notification.DomainEvent.User; _logger.LogInformation($"User {user.Name} Registered"); var registerData = new RegisterMailData() { Username = user.Name }; var templateData = new MailTemplateData(user.Email, "Bienvenido a Clean Architecture Example!"); await _mailService.Enqueue(templateData, typeof(IRegisterMail), registerData); }
private async Task SendDisablementMail(User user, UserDisablement userDisablement) { var disablementMailData = new DisablementMailData() { DisablementTypeId = userDisablement.DisablementTypeId, DisablementType = userDisablement.DisablementType.Description, Username = user.Name, Observation = userDisablement.Observation }; var subject = userDisablement.DisablementTypeId == GeneralConstants.DisablementUnblockedId ? "Su cuenta ha sido habilitada" : "Su cuenta ha sido deshabilitada"; var mailData = new MailTemplateData(user.Email, subject); await _mailService.Enqueue(mailData, typeof(IDisablementMail), disablementMailData); }
private async Task SendNewLoginMail(User user, UserLogin userLogin) { var newLoginData = new NewLoginMailData() { Username = user.Name, Device = userLogin.Device, DeviceType = userLogin.DeviceType, Browser = userLogin.Browser, Ip = userLogin.ClientIp.MapToIPv4().ToString(), Country = userLogin.Country, Region = userLogin.Region, City = userLogin.City, Latitude = userLogin.Latitude, Longitude = userLogin.Longitude, }; var templateData = new MailTemplateData(user.Email, "Se ha detectado un nuevo inicio de sesión"); await _mailService.Enqueue(templateData, typeof(INewLoginMail), newLoginData); }
public async Task Send <TData>(MailTemplateData mailData, Type template, TData data) { var mailTemplate = _serviceProvider.GetRequiredService(template); if (!(mailTemplate is IMailTemplate <TData>)) { throw new ArgumentException($"{template.FullName} debe implementar la interfaz {typeof(IMailTemplate<>).FullName}"); } (mailTemplate as IMailTemplate <TData>).Data = data; var templateName = mailTemplate.GetType().FullName ?? ""; templateName = templateName.Substring(0, templateName.Length - 5); var body = await _viewRenderer.Render(templateName, mailTemplate); await _email .To(mailData.Emails.Select(email => new Address(email)).ToList()) .Subject(mailData.Subject) .Body(body, isHtml: true) .SendAsync(); }
public Task Send <TData>(MailTemplateData mailData, Type template, TData data) { return(Task.CompletedTask); }
public Task <string> Enqueue <TData>(MailTemplateData mailData, Type template, TData data) { return(Task.FromResult("")); }
public override MailMessage Save(int id, string from, List <string> to, List <string> cc, List <string> bcc, string mimeReplyToId, bool importance, string subject, List <int> tags, string body, List <MailAttachmentData> attachments, string calendarIcs, DeliveryFailureMessageTranslates translates = null) { var mailAddress = new MailAddress(from); var engine = new EngineFactory(Tenant, User); var accounts = engine.AccountEngine.GetAccountInfoList().ToAccountData(); var account = accounts.FirstOrDefault(a => a.Email.ToLower().Equals(mailAddress.Address)); if (account == null) { throw new ArgumentException("Mailbox not found"); } if (account.IsGroup) { throw new InvalidOperationException("Saving emails from a group address is forbidden"); } var mbox = engine.MailboxEngine.GetMailboxData( new СoncreteUserMailboxExp(account.MailboxId, Tenant, User)); if (mbox == null) { throw new ArgumentException("No such mailbox"); } string mimeMessageId, streamId; var previousMailboxId = mbox.MailBoxId; if (id > 0) { var message = engine.MessageEngine.GetMessage(id, new MailMessage.Options { LoadImages = false, LoadBody = true, NeedProxyHttp = Defines.NeedProxyHttp, NeedSanitizer = false }); if (message.Folder != FolderType.Templates) { throw new InvalidOperationException("Saving emails is permitted only in the Templates folder"); } if (message.HtmlBody.Length > Defines.MaximumMessageBodySize) { throw new InvalidOperationException("Message body exceeded limit (" + Defines.MaximumMessageBodySize / 1024 + " KB)"); } mimeMessageId = message.MimeMessageId; streamId = message.StreamId; /* * if (attachments != null && attachments.Any()) * { * foreach (var attachment in attachments) * { * attachment.streamId = streamId; * } * } */ previousMailboxId = message.MailboxId; } else { mimeMessageId = MailUtil.CreateMessageId(); streamId = MailUtil.CreateStreamId(); } var fromAddress = MailUtil.CreateFullEmail(mbox.Name, mbox.EMail.Address); var template = new MailTemplateData(id, mbox, fromAddress, to, cc, bcc, subject, mimeMessageId, mimeReplyToId, importance, tags, body, streamId, attachments, calendarIcs) { PreviousMailboxId = previousMailboxId }; DaemonLabels = translates ?? DeliveryFailureMessageTranslates.Defauilt; return(Save(template)); }