private void SendMailActivationAccount(UserDetails userModel) { try { string fullName = userModel.PreferredName == null ? userModel.FirstName : userModel.PreferredName != null ? userModel.PreferredName : string.Empty; string activateCode = AESSecurity.EncryptPassword(userModel.Email); MimeMessage emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("*****@*****.**", EmailConstant.EmailAddress)); emailMessage.To.Add(new MailboxAddress(fullName, userModel.Email)); emailMessage.Subject = "Acativation Your Account."; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = EmailConstant.AcctivationAccount(fullName, HttpContext.Request.Scheme, HttpContext.Request.Host.Value, userModel.UserID, activateCode) }; using (SmtpClient mailClient = new SmtpClient()) { mailClient.Connect(EmailConstant.SmtpServer, EmailConstant.SmtpPort, MailKit.Security.SecureSocketOptions.StartTlsWhenAvailable); mailClient.AuthenticationMechanisms.Remove("XOAUTH2"); mailClient.Authenticate(EmailConstant.SmtpUsername, EmailConstant.SmtpPassword); mailClient.Send(emailMessage); mailClient.Disconnect(true); mailClient.Dispose(); } } catch (MySqlException sqlEx) { sqlEx.Message.ToString(); } catch (ArgumentException arEx) { throw new ArgumentException("Your Exception : " + arEx.Message.ToString()); } catch (Exception ex) { throw new Exception("Your Exception : " + ex.Message.ToString()); } }
private void SendMailForgotPassword(string userId, string userName, string email) { try { MimeMessage emailMessage = new MimeMessage(); emailMessage.From.Add(new MailboxAddress("*****@*****.**", EmailConstant.EmailAddress)); emailMessage.To.Add(new MailboxAddress(userName, email)); emailMessage.Subject = "Reset Password."; emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = EmailConstant.ForgotPassword(userName, HttpContext.Request.Scheme, HttpContext.Request.Host.Value, AESSecurity.EncryptPassword(userId), AESSecurity.EncryptPassword(userName), AESSecurity.EncryptPassword(email)) }; using (SmtpClient mailClient = new SmtpClient()) { mailClient.Connect(EmailConstant.SmtpServer, EmailConstant.SmtpPort, MailKit.Security.SecureSocketOptions.StartTlsWhenAvailable); mailClient.AuthenticationMechanisms.Remove("XOAUTH2"); mailClient.Authenticate(EmailConstant.SmtpUsername, EmailConstant.SmtpPassword); mailClient.Send(emailMessage); mailClient.Disconnect(true); mailClient.Dispose(); } } catch (MySqlException sqlEx) { sqlEx.Message.ToString(); } catch (ArgumentException arEx) { throw new ArgumentException("Your Exception : " + arEx.Message.ToString()); } catch (Exception ex) { throw new Exception("Your Exception : " + ex.Message.ToString()); } }