private void OnNewAddMessageCommand() { try { if (!hasSMTPConfig) { throw new MissingMemberException(); } if (EMailCollection == null) { EMailCollection = new ObservableCollection <EMailResponseObjectModel>(); } emailObject.FromAddress = FromAddress; emailObject.ToAddress = ToAddress; emailObject.MessageBody = MessageBody; emailObject.Subject = Subject; if (!EMailCollection.Contains(emailObject)) { EMailCollection.Add(emailObject); ResponseObjectModel.HasConfiguration = true; } } catch (Exception mailAddEx) { if (mailAddEx.GetType() == typeof(MissingMemberException)) { if (new MessageBoxViewModel { Caption = "No SMTP Server configured", Message = "Are your sure to proceed without any smtp configuration? 'localhost' will be used instead", Buttons = MessageBoxButton.YesNo, Image = MessageBoxImage.Question } .Show(this.Dialogs) == MessageBoxResult.Yes) { emailObject.SMTPServerName = "localhost"; emailObject.UseDefaultCredentials = true; hasSMTPConfig = true; } } else { new MessageBoxViewModel { Caption = "Unconfigured Response", Message = string.Format("{0} \n{1}", mailAddEx.Message, mailAddEx.InnerException == null ? "" : mailAddEx.InnerException.ToString()), Buttons = MessageBoxButton.OK, Image = MessageBoxImage.Exclamation } .Show(this.Dialogs); } } Ok(); }
private static EMail FindEmail(string address, EMailCollection emails) { if (string.IsNullOrEmpty(address)) { return(null); } foreach (EMail email in emails) { if (address.Equals(email.Address, StringComparison.InvariantCultureIgnoreCase)) { return(email); } } return(null); }