/// <summary> /// Updates the data. /// </summary> private void UpdateData() { StatusUpdate.StatusMessage = Utilities.GetResourceValue("Loading"); try { if (ValidateData()) { SmtpDetail mailDetails = FillData(null); int result = SmtpDataAccess.UpdateSmtpDetails(mailDetails); if (result > 0) { NotificationHelper.ShowMessage(Utilities.GetResourceValue("DataUpdateSuccess"), Utilities.GetResourceValue("CaptionInfo")); LoadData(); } else { NotificationHelper.ShowMessage(Utilities.GetResourceValue("NothingUpdated"), Utilities.GetResourceValue("CaptionWarning")); } } } catch (Exception exception) { string message = exception.Message; if (exception.InnerException != null) { message += Environment.NewLine + exception.InnerException.Message; } NotificationHelper.ShowMessage(message, Utilities.GetResourceValue("CaptionError")); } StatusUpdate.StatusMessage = Utilities.GetResourceValue("DefaultStatus"); }
/// <summary> /// Loads the data. /// </summary> /// <param name="data">The data.</param> /// <returns></returns> private SmtpDetail FillData(SmtpDetail data) { if (data == null) { data = new SmtpDetail(); } data.EnableSsl = Settings.EnableSsl; data.FromMail = Settings.FromMail; data.Id = Settings.Id; data.NotificationFrequency = (byte)Settings.NotificationFrequency; data.NotificationsEnabled = Settings.NotificationsEnabled; data.PortNumber = Settings.PortNumber; data.SenderName = Settings.SenderName; data.SmtpServer = Settings.SmtpServer; data.ToMail = Settings.ToMail; data.UserAuthentication = Settings.UserAuthentication ? 1 : 0; data.UserName = Settings.UserName; if (Settings.OldPassword != Settings.Password) { data.SetPassword(Settings.Password); } data.ModifiedTime = Constants.CurrentTime; return(data); }
/// <summary> /// Loads the data. /// </summary> private void LoadData() { SmtpDetail data = SmtpDataAccess.GetSmtpDetails(); if (data != null) { LoadData(data); } }
/// <summary> /// Loads the data. /// </summary> /// <param name="data">The data.</param> private void LoadData(SmtpDetail data) { Settings.EnableSsl = data.EnableSsl; Settings.FromMail = data.FromMail; Settings.Id = data.Id; Settings.NotificationFrequency = (NotificationFrequency)Enum.Parse(typeof(NotificationFrequency), data.NotificationFrequency.ToString(Constants.DefaultCulture)); Settings.NotificationsEnabled = data.NotificationsEnabled; Settings.ConfirmPassword = Settings.OldPassword = Settings.Password = data.Password; Settings.PortNumber = data.PortNumber; if (!string.IsNullOrEmpty(data.SenderName)) { Settings.SenderName = data.SenderName; } Settings.SmtpServer = data.SmtpServer; Settings.ToMail = data.ToMail; Settings.UserAuthentication = data.UserAuthentication == 1; Settings.UserName = data.UserName; }
public static void EmailSetting(int appId, int appTypeid, string emailType, out SmtpEmail smtpEmailObj, out EmailGroup objEmailGroup, out string mailTo) { EmailGroupDal objEmailGroupDal = new EmailGroupDal(); EmailConfigDetailDal objEmailConfigDetailDal = new EmailConfigDetailDal(); #region smtp Setting SmtpDetailsDal objSmtpDetailsDal = new SmtpDetailsDal(); try { SmtpDetail objSmtpDetail = objSmtpDetailsDal.GetAtiveSmtpDetails(); SmtpEmail.SmtpHost = objSmtpDetail.SmtpHost; SmtpEmail.SmtpUser = objSmtpDetail.SmtpUser; SmtpEmail.SmtpPwd = objSmtpDetail.Password; smtpEmailObj = SmtpEmail.GetSmtpEmailInstance(); #endregion //"Validation" to appconfig objEmailGroup = objEmailGroupDal.GetEmailGroupByApptypeIdAndEmailType(appTypeid, emailType); #region Emailto Setting var toemailList = objEmailConfigDetailDal.GetEmailListByGroupIdAndAppId(objEmailGroup.Id, appId); mailTo = ""; for (int index = 0; index < toemailList.Count; index++) { if (index == toemailList.Count - 1) { mailTo += toemailList[index]; } else { mailTo += toemailList[index] + ","; } } } catch (Exception ex) { throw; } #endregion }
/// <summary> /// Sends the test mail. /// </summary> /// <param name="mailDetails">The mail details.</param> /// <returns></returns> private static bool SendTestMail(SmtpDetail mailDetails) { bool result = MailService.SendMail(mailDetails, Utilities.GetResourceValue("MailSubjectTest"), GetNotificationMailBody()); return(result); }
public void SendEmails() { try { var emailDetail = emailTrackingRepository.FindAll().Where(x => x.EmailStatus.Equals((int)EmailStatusType.Ready)).OrderBy(x => x.CreatedAt).Take(10).ToList(); SingletonLogger.Instance.Debug("Ready Emails are :" + emailDetail.Count()); smtpDetail = smtpDetailsRepository.Find(1);//TODO static value replace later SingletonLogger.Instance.Debug("Email Send From " + smtpDetail.SmtpUser); smtpMail = new SmtpMail(smtpDetail.SmtpHost, smtpDetail.SmtpUser, smtpDetail.Password); foreach (var email in emailDetail) { RunDetail runDetail = runDetailsRepository.Find(email.RunNumberId); SingletonLogger.Instance.Debug("Email Id = " + email.EmailTrackingId); if (string.IsNullOrEmpty(email.EmailToIds)) { SingletonLogger.Instance.Debug("To email Ids not found in DB."); continue; } SingletonLogger.Instance.Debug("Email Sending To " + email.EmailToIds); smtpMail.To = email.EmailToIds; smtpMail.From = smtpDetail.SmtpUser; smtpMail.Subject = email.Subjects.Replace("{{RUN_NUMBER}}", runDetail.RunNumber); smtpMail.Body = email.Body.Replace("{{RUN_NUMBER}}", runDetail.RunNumber); if (!string.IsNullOrEmpty(email.EmailCcIds)) { smtpMail.Cc = email.EmailCcIds; } try { SingletonLogger.Instance.Debug("Start Sending Email"); var result = smtpMail.SendEmail(); if (string.IsNullOrEmpty(result)) { email.EmailStatus = (int)EmailStatusType.Success; SingletonLogger.Instance.Debug("Email Status Set to SUCCESS"); email.SentMessage = "Email sent successfully."; SingletonLogger.Instance.Debug("Email sent successfully"); } else { SingletonLogger.Instance.Error("Error in sending email. Detail : " + result); email.EmailStatus = (int)EmailStatusType.Error; email.SentMessage = result; } } catch (Exception ex) { SingletonLogger.Instance.Error("Error in sending email. Detail : " + ex.ToString()); email.EmailStatus = (int)EmailStatusType.Error; email.SentMessage = ex.Message; } //update entry SingletonLogger.Instance.Debug("Updating Status in Email Tracking table with Id = " + email.EmailTrackingId); email.Status = true; email.SentDate = DateTime.Now; emailTrackingRepository.Save(email); SingletonLogger.Instance.Debug("Updated Status " + email.Status + " in Email Tracking table successfully"); } SingletonLogger.Instance.Debug("Email component Complete"); } catch (Exception ex) { SingletonLogger.Instance.Error(ex.ToString()); } }