public void init(libCampaignReactor.Models.Campaign campaign) { this.campaign = campaign; }
public CreatePage(libCampaignReactor.Models.Campaign campaign) { this.init(campaign); InitializeComponent(); }
public async void send(libCampaignReactor.Models.Campaign campaign) { MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; List<libCampaignReactor.Models.Bot> bots = mainWindow.client.getAvailableBots(); if (bots.Count > 0) { ProgressDialogController progresDialogController = await mainWindow.ShowProgressAsync("Sending...", "Progress message"); int numberOfBotsSent = 0; progresDialogController.SetProgress(numberOfBotsSent / bots.Count); foreach (libCampaignReactor.Models.Bot bot in bots) { this.sendCampaign(campaign, bot); mainWindow.client.markBotAsSent(bot); numberOfBotsSent++; progresDialogController.SetProgress(numberOfBotsSent/bots.Count); } await progresDialogController.CloseAsync(); //mainWindow.showDialogue("Send Complete", "All messages have been queued for delivery!"); } else { mainWindow.showDialogue("Unable to Send", "There are currently no available bots!"); } }
public async Task sendCampaign(libCampaignReactor.Models.Campaign campaign, libCampaignReactor.Models.Bot bot) { MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; List<libCampaignReactor.Models.Subscriber> subscribers = mainWindow.client.getSendQueueByBotId(bot.id); libCampaignReactor.Models.Host host = mainWindow.client.getNextHost(); if (subscribers.Count > 0) { foreach (libCampaignReactor.Models.Subscriber subscriber in subscribers) { libCampaignReactor.Models.BitlyAccount bitlyAccount = mainWindow.client.getNextBitlyAccount(); MailMessage message = new MailMessage(); message.From = new MailAddress(bot.emailAddress, $"{bot.firstName} {bot.lastName}"); message.To.Add(subscriber.emailAddress); message.Subject = campaign.subject; message.Body = campaign.subject; int sendTime = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; string campaignUrl = mainWindow.client.shortenUrl(bitlyAccount, $"http://campaignreactor.com:3579/event_log/click/?cid={campaign.id}&bid={bot.id}&hid={host.id}&svid={host.serverId}&sid={subscriber.id}&uid=1&st={sendTime}"); string campaignImageUrl = mainWindow.client.shortenUrl(bitlyAccount, $"http://campaignreactor.com:3579/event_log/open/?cid={campaign.id}&bid={bot.id}&hid={host.id}&svid={host.serverId}&sid={subscriber.id}&uid=1&st={sendTime}"); string campaignUnsubscribeUrl = mainWindow.client.shortenUrl(bitlyAccount, $"http://campaignreactor.com:3579/event_log/unsubscribe/?cid={campaign.id}&bid={bot.id}&hid={host.id}&svid={host.serverId}&sid={subscriber.id}&uid=1&st={sendTime}"); string campaignUnsubscribeImageUrl = mainWindow.client.shortenUrl(bitlyAccount, $"http://campaignreactor.com:3579/campaign/unsubscribe_image/?cid={campaign.id}&bid={bot.id}&hid={host.id}&svid={host.serverId}&sid={subscriber.id}&uid=1&st={sendTime}"); AlternateView html = AlternateView.CreateAlternateViewFromString($"<center><a href=\"{campaignUrl}\">{campaign.subject}</a><br/><br/><a href=\"{campaignUrl}\"><img style=\"width=\"300px\" height=\"200px\" src=\"{campaignImageUrl}\" /></a><br/><br/><a href=\"{campaignUnsubscribeUrl}\"><img style=\"width=\"300px\" height=\"200px\" src=\"{campaignUnsubscribeImageUrl}\" /></a></center>"); html.ContentType = new System.Net.Mime.ContentType("text/html"); message.AlternateViews.Add(html); SmtpClient smtpClient = new SmtpClient("smtp.mail.yahoo.com", 587); smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpClient.EnableSsl = true; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential(bot.emailAddress, bot.password); smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted); try { smtpClient.SendAsync(message, message); } catch (Exception exception) { mainWindow.showDialogue("Exception", exception.Message); } } } }
private async void confirmSend(libCampaignReactor.Models.Campaign campaign) { MainWindow mainWindow = (MainWindow)Application.Current.MainWindow; MessageDialogResult result = await mainWindow.ShowMessageAsync("Confirm", "Would you like to proceed?", MessageDialogStyle.AffirmativeAndNegative); if (result == MessageDialogResult.Affirmative) { this.send(mainWindow.client.getCampaignById(campaign.id)); } }