public void Initialize() { _smtpClientMock = new Mock <SmtpClient>(); var temapltesPath = new Dictionary <string, string>(); var pathFolders = AppContext.BaseDirectory.Split('\\').ToList(); if (string.IsNullOrWhiteSpace(pathFolders[pathFolders.Count - 1])) { pathFolders = pathFolders.Take(pathFolders.Count - 1).ToList(); } pathFolders[0] += '\\'; pathFolders = pathFolders.Take(pathFolders.Count - 3).ToList(); pathFolders.Add("MediaShop.WebApi"); pathFolders.Add("Content"); pathFolders.Add("Templates"); var templatesFoldePath = Path.Combine(pathFolders.ToArray()); temapltesPath.Add("AccountConfirmationEmailTemplate", Path.Combine(templatesFoldePath, "AccountConfirmationEmailTemplate.html")); temapltesPath.Add("AccountPwdRestoreEmailTemplate", Path.Combine(templatesFoldePath, "AccountPwdRestoreEmailTemplate.html")); IEmailSettingsConfig emailConf = new EmailSettingsConfig("smtp.gmail.com", 587, "*****@*****.**", "ayTYh?2-3xtUB26j", temapltesPath); _mailService = new EmailService(_smtpClientMock.Object, emailConf); _confirmDto = new AccountConfirmationDto() { Token = TokenHelper.NewToken(), Email = "*****@*****.**" }; _restoreDto = new AccountPwdRestoreDto() { Token = TokenHelper.NewToken(), Email = "*****@*****.**" }; }
public async Task SendRestorePwdLinkAsync(AccountPwdRestoreDto model) { var htmlBody = await GetTemplateTextAsync("AccountPwdRestoreEmailTemplate").ConfigureAwait(false); htmlBody = string.Format(htmlBody, model.Origin, HttpUtility.UrlEncode(model.Email), HttpUtility.UrlEncode(model.Token)); var message = new MimeMessage(); message.From.Add(new MailboxAddress("Media shop", ((NetworkCredential)_config.Credentials).UserName)); message.To.Add(new MailboxAddress(model.Email)); message.Subject = "Password restore"; var builder = new BodyBuilder(); builder.HtmlBody = htmlBody; message.Body = builder.ToMessageBody(); await ConnectClientAsync().ContinueWith(t => AutenticateClientAsync().ContinueWith(tt => SendEmailAsync(message))).ConfigureAwait(false); }
/// <summary> /// Method for send restore link /// </summary> /// <exception cref="EmailTemplatePathException"></exception> /// <exception cref="FileNotFoundException"></exception> /// <exception cref="CountOfTryToEmailSendException"></exception> /// <param name="model"></param> public void SendRestorePwdLink(AccountPwdRestoreDto model) { var htmlBody = GetTemplateText("AccountPwdRestoreEmailTemplate"); htmlBody = string.Format(htmlBody, model.Origin, HttpUtility.UrlEncode(model.Email), HttpUtility.UrlEncode(model.Token)); var message = new MimeMessage(); message.From.Add(new MailboxAddress("Media shop", ((NetworkCredential)_config.Credentials).UserName)); message.To.Add(new MailboxAddress(model.Email)); message.Subject = "Password restore"; var builder = new BodyBuilder(); builder.HtmlBody = htmlBody; message.Body = builder.ToMessageBody(); ConnectClient(); AutenticateClient(); SendEmail(message); }