private void Page_Loaded(object sender, RoutedEventArgs e) { if (CampId != 0) { CampaignManagement campaignManagement = new CampaignManagement(UserId, DateTime.Today, CampaignId: CampId); Campaign camp = campaignManagement.GetCampaign(); CampaignNameTb.Text = camp.Camp_Name; CampaignDtlsTb.Text = camp.Camp_Dtls; ListTb.Text = camp.Emlist_Id; TemplatesTb.Text = camp.Tmp_Id.ToString(); Status.Text = camp.Camp_ACStat; StatGrid.Visibility = Visibility.Visible; CampDate.SelectedDate = camp.Camp_Date; PauseBtn.Visibility = Visibility.Visible; DeleteBtn.Visibility = Visibility.Visible; if (camp.Camp_ACStat == "Active") { PauseBtn.DisplayText = "Pause"; PauseBtn.ImgSource = new BitmapImage( new Uri("pack://application:,,,/Mailarn;component/icos/pause.png")); } else { PauseBtn.DisplayText = "Resume"; PauseBtn.ImgSource = new BitmapImage( new Uri("pack://application:,,,/Mailarn;component/icos/play.png")); } } }
public RunCampaign(int UserId, int CampaignID, int EmailListId) { CampaignManagement campaignmanagement = new CampaignManagement(UserId, DateTime.Now, CampaignId: CampaignID); Campaign campaign = campaignmanagement.GetCampaign(); UserManagement userManagement = new UserManagement(UserId); User user = userManagement.GetUserById(); string[] emailListIds = new string[] { campaign.Emlist_Id }; if (campaignmanagement.emaillistid.Contains(',')) { emailListIds = campaignmanagement.emaillistid.Split(',').ToArray(); } if (!CampaignCompleted(campaign)) { Parallel.For(0, emailListIds.Length, index => { int listId = Convert.ToInt32(emailListIds[index]); EmailListManagement emailListManagement = new EmailListManagement(UserId, EmailListId: listId); Email[] emails = emailListManagement.GetAllEmailsFromList(); UserAuth auth = new UserAuth(); SmtpClient client = auth.Authenticate(); var message = new MimeMessage(); List <MailboxAddress> recepients = new List <MailboxAddress>(); for (int i = 0; i < emails.Length; i++) { message.To.Add(new MailboxAddress(emails[i].F_Name, emails[i].Email_Add)); } message.From.Add(new MailboxAddress("Arrivarn", campaign.Sender_Email)); message.Subject = campaign.Eml_Subject; var bodyBuilder = new BodyBuilder { HtmlBody = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "\\Emails\\" + campaign.Tmp_Id + "XX" + campaign.Tmp_Name) }; message.Body = bodyBuilder.ToMessageBody(); client.Send(message); client.Disconnect(true); }); } ; }