/// <summary> /// Delete this address from the database, and fire the Deleted event. /// </summary> public void Delete() { using (var db = new MailerEntities()) { db.Addresses.Attach(Address); db.MailingListLines.RemoveRange(Address.MailingListLines); db.ReceivedMails.RemoveRange(Address.ReceivedMails); db.Addresses.Remove(Address); db.SaveChanges(); } MessagePump.Dispatch(this, "AddressDeleted"); }
/// <summary> /// Delete the underlying MailingList from the database. /// </summary> public void Delete() { if (!CanChange) { throw new InvalidOperationException("Cannot delete this mailing list"); } using (var db = new MailerEntities()) { db.MailingLists.Attach(MailingList); db.MailingListLines.RemoveRange(MailingList.MailingListLines); db.MailingLists.Remove(MailingList); db.SaveChanges(); } MessagePump.Dispatch(this, "MailingListDeleted"); }
/// <summary> /// Open an EditAddress dialog for editing this address. /// </summary> /// <returns>The DialogResult of the underlying EditAddress window.</returns> public bool?Edit() { var addrWind = new EditAddress(new EditAddressViewModel(Address)); addrWind.ShowDialog(); using (var db = new MailerEntities()) { Address = db.Addresses.Find(Address.AddressID); } OnPropertyChanged("FirstName"); OnPropertyChanged("LastName"); OnPropertyChanged("Email"); MessagePump.Dispatch(this, "AddressChanged"); return(addrWind.DialogResult); }
/// <summary> /// Open a new EditMailingList window to edit the current mailing list. /// </summary> public void Edit() { if (!CanChange) { throw new InvalidOperationException("Cannot edit this mailing list"); } var mailWind = new EditMailingList(new EditMailingViewModel(MailingList)); mailWind.ShowDialog(); using (var db = new MailerEntities()) { MailingList = db.MailingLists.Find(MailingList.ListID); countAddresses = MailingList.MailingListLines.Count; } OnPropertyChanged("Name"); OnPropertyChanged("Subtext"); MessagePump.Dispatch(this, "MailingListChanged"); }
public void Send(string fromName, string fromEmail) { if (fromName == "") { throw new ArgumentException("Must input a From name."); } if (fromEmail == "") { throw new ArgumentException("Must input a From email."); } if (Subject == "") { throw new ArgumentException("Subject cannot be empty."); } if (Body == "") { throw new ArgumentException("Body cannot be empty."); } if (Recipients.Count == 0) { throw new ArgumentException("Must specify recipients."); } MailAddress fromAddress; try { fromAddress = new MailAddress(fromEmail, fromName); } catch (Exception) { throw new ArgumentException("From address is not valid."); } var client = new Client("smtp.mailgun.org", 587) { // Don't waste your time, spammers. This account has since been deleted // after this repo was made public. // (The PW had to be in source somewhere so our prof could run the app. // Putting it here was the simplest solution, and this repo used to be private anyway). // I'm still going to leave somewhat valid looking credentials here // so you can waste a little bit of your time when your scraper comes across it. // If you were scraping really hard, you could get the old (still invalid) creds from the history. UserName = "******", Password = "******" }; var message = new Mail.Message(client) { Subject = Subject, Body = Body, From = fromAddress }; foreach (var rvm in Recipients) { if (rvm is AddressRecipientViewModel) { message.AddRecipient((rvm as AddressRecipientViewModel).Address); } else if (rvm is MailingListRecipientViewModel) { var mailingList = (rvm as MailingListRecipientViewModel).MailingList; if (mailingList is DynamicMailingList) { message.AddRecipient(mailingList as DynamicMailingList); } else { message.AddRecipient(mailingList); } } } foreach (var attachment in Attachments) { message.AddAttachment(attachment.FullPath); } Task.Run(() => { message.Send(); MessageBox.Show("Sent!"); Application.Current.Dispatcher.BeginInvoke( new Action(() => MessagePump.Dispatch(this, "MessageSent")), new object[0] ); }); }