/// <summary> /// Sends the email. /// </summary> /// <exception cref="System.ArgumentNullException"> /// emailEntity /// or /// iCal /// or /// inbox /// </exception> private static void SendEmail(SentEmailMessage emailEntity, iCalendar iCal, TenantEmailSetting emailServerSettings) { if (emailEntity == null) { throw new ArgumentNullException("emailEntity"); } if (iCal == null) { throw new ArgumentNullException("iCal"); } if (emailServerSettings == null) { throw new ArgumentNullException("emailServerSettings"); } ///// // Send the email. ///// iCalEmailHelper.SendICalEmail(iCal, emailEntity.ToMailMessage( ), emailServerSettings); }
/// <summary> /// Send reset password Email. /// </summary> /// <param name="displayName">The display name.</param> /// <returns></returns> private bool SendEmail(UserAccount account, string email, string tenant) { bool successSentEmail = false; try { account = account.AsWritable <UserAccount>(); //only check current account is available or not if (account == null) { return(successSentEmail); } string key = EDC.Security.CryptoHelper.GetMd5Hash(account.Id.ToString()); if (account.PasswordReset != null) { account.PasswordReset.AsWritable <PasswordResetRecord>(); account.PasswordReset.Delete(); } account.PasswordReset = new PasswordResetRecord { PasswordResetKey = key, PasswordResetExpiry = DateTime.UtcNow.AddDays(1.0) }; account.Save(); EventLog.Application.WriteInformation("set password reset key {0}", key); var mail = new SentEmailMessage() { EmIsHtml = true, EmSentDate = DateTime.UtcNow, }; string accountFullName = account.AccountHolder.FirstName + " " + account.AccountHolder.LastName; if (accountFullName.Trim().Length == 0) { accountFullName = account.AccountHolder.Name; } //string toMail = email; const string subject = "Reset Password - ReadiNow"; string link = string.Format("{0}#/{1}/?key={2}&type=reset", Request.Headers.Referrer.ToString(), tenant, key); string mailBoday = string.Format("Hi {0} <br> <br> We've received a request to reset your account {1} password for email address {2} <br> If you didn't make the request, please contact your administrator. <br> Otherwise, you can reset your password using this link: {3} <br><br>Best Regards, <br>ReadiNow", accountFullName, account.Name, email, link); var emailServer = ReadiNow.Model.Entity.Get <TenantEmailSetting>("tenantEmailSettingsInstance", TenantEmailSetting.AllFields); if (!string.IsNullOrEmpty(emailServer.SmtpServer) && !string.IsNullOrEmpty(emailServer.EmailNoReplyAddress)) { EventLog.Application.WriteInformation("Send user {0} reset password email to account '{1}' by email '{2}'", accountFullName, account.Name, email); var sentMessage = new SentEmailMessage() { EmTo = email, EmFrom = emailServer.EmailNoReplyAddress, EmSubject = subject, EmBody = mailBoday, EmIsHtml = true, EmSentDate = DateTime.UtcNow, SentFromEmailServer = emailServer }; sentMessage.Save(); var sender = new SmtpEmailSender(emailServer); sender.SendMessages(sentMessage.ToMailMessage().ToEnumerable().ToList()); } successSentEmail = true; } catch (Exception ex) { EventLog.Application.WriteError("Send Email: Unhandled internal exception: " + ex.ToString()); } return(successSentEmail); }