public async void SendEmailForPasswordRecovery(string Email) { ConfigSendEmail config = new ConfigSendEmail(_configSendEmail); try { PasswordRecovery PasswordRecoveryModel = new PasswordRecovery(); PasswordRecoveryModel.ChangePasswordUrl = CommonContants.ForgotPasswordUrl; IMailService emailService = new MailService(); IDataStaticService dataService = new DataStaticService(_env); MailTemplate mailTemplate = dataService.GetMailTemplate(CommonContants.ForgotPassword); if (mailTemplate != null) { config.Receivers = new List <string>() { Email }; //send an email await emailService.SendMail(config, mailTemplate, PasswordRecoveryModel); } } catch (Exception e) { throw; } }
public RequestForgotPasswordForEmailHandler(IBusClient busClient, IHostingEnvironment env, IOptions <ConfigSendEmail> configSendMail, DbContextOptions <Models.MessageContext> messContext) { _busClient = busClient; _env = env; _configSendMail = configSendMail.Value; _messContext = messContext; }
public MessageController(IHostingEnvironment env, IBusClient rawRabbitBus, IMailService mailService, IOptions <ConfigSendEmail> configSendEmail) { _configSendEmail = configSendEmail.Value; _mailService = mailService; _rawRabbitBus = rawRabbitBus; _env = env; }
public AccountCreatedHandlers(IBusClient busClient, IHostingEnvironment env, IOptions <ConfigSendEmail> configSendMail, DbContextOptions <Models.MessageContext> context) { _busClient = busClient; _env = env; _configSendMail = configSendMail.Value; _context = context; }
public async Task SendMail(ConfigSendEmail configSendEmail, EmailTemplate mailTemplate, RequestResetPassword requestResetPassword) { var sender = configSendEmail.Sender; var username = configSendEmail.Username; var password = configSendEmail.Password; var host = configSendEmail.Host; var port = configSendEmail.Port.ConvertToInt(); var receiver = requestResetPassword.Email; var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("Vacation Tracking", sender)); emailMessage.To.Add(new MailboxAddress("", receiver)); emailMessage.Subject = mailTemplate.Subject; emailMessage.Body = new TextPart("html") { Text = string.Format(mailTemplate.Body, requestResetPassword.Email, requestResetPassword.Token) }; using (var client = new SmtpClient()) { // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS) client.ServerCertificateValidationCallback = (s, c, h, e) => true; await client.ConnectAsync(host, port, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); // Must be removed for Gmail SMTP await client.AuthenticateAsync(username, password); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } }
public async Task HandleAsync(AccountCreatedForEmail e, IMessageContext context) { //initiator new config for sending email ConfigSendEmail config = new ConfigSendEmail(_configSendMail); try { IMailService emailService = new MailService(); IDataStaticService dataService = new DataStaticService(_env); MailTemplate mailTemplate = dataService.GetMailTemplate(CommonContants.AccountCreated); if (mailTemplate != null) { config.Receivers = new List <string>() { e.Email }; //send an email await emailService.SendMail(config, mailTemplate, e); } Message message = new Message(); message.ReceiverId = e.Id; message.Content = mailTemplate.Body; message.Subject = mailTemplate.Subject; message.Type = Vacation.common.Enums.MessageType.AccountCreated; message.CreateAt = DateTime.Now; _messageService.Create(message); } catch (Exception ex) { throw new CustomException(ex.Message, ex.InnerException.Message); } }
public async Task SendMail <T>(ConfigSendEmail config, MailTemplate mailTemplate, T value) { try { var sender = config.Sender; var username = config.Username; var password = config.Password; var host = config.Host; var port = config.Port.ConvertToInt(); var emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress(sender)); emailMessage.To.AddRange(config.Receivers.Select(t => new MailboxAddress("", t))); mailTemplate = ReplaceHolderTemplate(mailTemplate, value); emailMessage.Subject = mailTemplate.Subject; mailTemplate.Body = mailTemplate.Body; emailMessage.Body = new TextPart("html") { Text = mailTemplate.Body }; using (var client = new SmtpClient()) { // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS) client.ServerCertificateValidationCallback = (s, c, h, e) => true; await client.ConnectAsync(host, port, false); client.AuthenticationMechanisms.Remove("XOAUTH2"); // Must be removed for Gmail SMTP await client.AuthenticateAsync(username, password); await client.SendAsync(emailMessage); await client.DisconnectAsync(true); } } catch (Exception e) { throw new CustomException("Errors.ERROR_SEND_EMAIL"); } }
public async Task HandleAsync(RequestForgotPasswordForEmail e, IMessageContext context) { ConfigSendEmail config = new ConfigSendEmail(_configSendMail); try { IMailService emailService = new MailService(); IDataStaticService dataService = new DataStaticService(_env); MailTemplate mailTemplate = dataService.GetMailTemplate(CommonContants.ForgotPassword); if (mailTemplate != null) { config.Receivers = new List <string>() { e.Email }; //send an email await emailService.SendMail(config, mailTemplate, e); } } catch (Exception ex) { throw new CustomException("CAN_NOT_SEND_EMAIL", ex.Message); } }
public async Task HandleAsync(AccountCreatedForEmail e, IMessageContext context) { //initiator new config for sending email ConfigSendEmail config = new ConfigSendEmail(_configSendMail); try { IMailService emailService = new MailService(); IDataStaticService dataService = new DataStaticService(_env); MailTemplate mailTemplate = dataService.GetMailTemplate(CommonContants.AccountCreated); if (mailTemplate != null) { config.Receivers = new List <string>() { e.Email }; //send an email await emailService.SendMail(config, mailTemplate, e); } } catch (Exception) { throw; } }
public AccountController(IAccountService accountService, IOptions <EmailTemplate> emailTemplate, IOptions <ConfigSendEmail> configSendEmail) { _accountService = accountService; _emailTemplate = emailTemplate.Value; _configSendEmail = configSendEmail.Value; }