//This Method is Send the Mail
        private async Task SendEmail(UserEmailOptionsModel userEmailOptions)
        {
            //This is the Structure of  MailMesssage
            MailMessage mailMessage = new MailMessage
            {
                Subject    = userEmailOptions.Subject,
                Body       = userEmailOptions.Body,
                From       = new MailAddress(_smtpConfig.SenderAddress, _smtpConfig.SenderDisplayName),
                IsBodyHtml = _smtpConfig.IsBodyHtml
            };

            foreach (var toEmail in userEmailOptions.ToEmails)
            {
                mailMessage.To.Add(toEmail);
            }

            //We require NetworkCredential for theUserName And Password for SmTp Service
            NetworkCredential networkCredential = new NetworkCredential(_smtpConfig.UserName, _smtpConfig.Password);

            //Now we have to create SMTP Clinet and by using  that client we had to send the Mail

            SmtpClient smtpClient = new SmtpClient
            {
                Host                  = _smtpConfig.Host,
                Port                  = _smtpConfig.Port,
                EnableSsl             = _smtpConfig.EnableSSL,
                UseDefaultCredentials = _smtpConfig.UseDefaltCredentials,
                Credentials           = networkCredential
            };

            mailMessage.BodyEncoding = Encoding.Default;
            await smtpClient.SendMailAsync(mailMessage);
        }
 private async Task SendForgotPasswordEmail(ApplicationUser user, string token)
 {
     string appDomain              = _configuration.GetSection("Application:AppDomain").Value;
     string confirmationLink       = _configuration.GetSection("Application:ForgotPassword").Value;
     UserEmailOptionsModel Options = new UserEmailOptionsModel
     {
         ToEmails = new List <string>()
         {
             user.Email
         },
         Placeholders = new List <KeyValuePair <string, string> >()
         {
             new KeyValuePair <string, string>("{{UserName}}", user.FirstName),
             new KeyValuePair <string, string>("{{link}}", string.Format(appDomain + confirmationLink, user.Id, token))
         }
     };
     await _emailService.SendEmailForForgotPassword(Options);
 }
 //This Method will send the Email For EmailConfirmation
 public async Task SendEmailForEmailConfirmation(UserEmailOptionsModel userEmailOptionsModel)
 {
     userEmailOptionsModel.Subject = UpdatePlaceHolders("Hello {{UserName}} Confirm Your Email", userEmailOptionsModel.Placeholders);
     userEmailOptionsModel.Body    = UpdatePlaceHolders(GetEmailBody("EmailConfirm"), userEmailOptionsModel.Placeholders);
     await SendEmail(userEmailOptionsModel);
 }
 public async Task SendEmailForForgotPassword(UserEmailOptionsModel userEmailOptionsModel)
 {
     userEmailOptionsModel.Subject = UpdatePlaceHolders("Hello {{UserName}} Reset your Password", userEmailOptionsModel.Placeholders);
     userEmailOptionsModel.Body    = UpdatePlaceHolders(GetEmailBody("ForgotPassword"), userEmailOptionsModel.Placeholders);
     await SendEmail(userEmailOptionsModel);
 }
 //This Method is used to Send the TestEmail
 public async Task SendTestEmail(UserEmailOptionsModel userEmailOptionsModel)
 {
     userEmailOptionsModel.Subject = UpdatePlaceHolders("Reminder For Delivery Leave From Narender / Bookstore", userEmailOptionsModel.Placeholders);
     userEmailOptionsModel.Body    = UpdatePlaceHolders(GetEmailBody("TestEmail"), userEmailOptionsModel.Placeholders);
     await SendEmail(userEmailOptionsModel);
 }