private void CreateAndSendEmailMessageFromTemplate(WebHookEvent evt)
        {
            var metadata = ParseMetadataFromMandrill(evt);
            var message = new Mandrill.EmailMessage();

            message.to = new List<Mandrill.EmailAddress>()
                    {
                        new EmailAddress{
                            email = "*****@*****.**"
                        },
                        new EmailAddress{
                            email = "*****@*****.**"
                        }
                    };

            message.subject = String.Format("Bounced email notification", evt.Event);
            message.from_email = "*****@*****.**";

            if (metadata.ContainsKey("CustID"))
                message.AddGlobalVariable("customerID", metadata["CustID"].ToUpper());
            else
                message.AddGlobalVariable("customerID", "Unknown");
            message.AddGlobalVariable("bouncedEmailAddress", evt.Msg.Email);
            message.AddGlobalVariable("application", GetSendingApplicationName(evt));
            message.AddGlobalVariable("timesent", TimeZoneInfo.ConvertTimeFromUtc(evt.Msg.TimeStamp, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time")).ToString());

            _mandrillApi.SendMessage(message, "mandrill-email-bounce", null);
        }
        private static Dictionary<string, string> ParseMetadataFromMandrill(WebHookEvent evt)
        {
            var metadata = new Dictionary<string, string>();

            if (evt.Msg.Metadata != null)
            {
                metadata = evt.Msg.Metadata.ToDictionary(m => m.Key, m => m.Value);
            }
            return metadata;
        }
        private static void CreateAndSendEmailMessage(WebHookEvent evt)
        {
            var metadata = ParseMetadataFromMandrill(evt);
            var message = new Mandrill.EmailMessage();

            message.to = new List<Mandrill.EmailAddress>()
                    {
                        new EmailAddress{
                            email = "*****@*****.**"
                        }
                    };

            message.subject = String.Format("TEST Bounced email notification", evt.Event);
            message.from_email = "*****@*****.**";

            StringBuilder body = new StringBuilder();
            body.AppendFormat("An email being sent to {0} has bounced.", evt.Msg.Email).AppendLine();
            body.AppendFormat("Email sent from address: {0}", evt.Msg.Sender).AppendLine();
            body.AppendFormat("Email subject line: {0}", evt.Msg.Subject).AppendLine();
            body.AppendLine();
            body.AppendLine("Please contact the customer and get an updated email address, or remove this email address from all systems.");
            body.AppendLine("This includes: Goldmine, JobTracker & SecureFTP");
            body.AppendFormat("Message sent at: {0}", TimeZoneInfo.ConvertTimeFromUtc(evt.Msg.TimeStamp, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"))).AppendLine();
            body.AppendLine("----");

            if (metadata.ContainsKey("CustID"))
            {
                body.AppendFormat("Customer ID: {0}", metadata["CustID"]);
                body.AppendLine();
            }

            if (evt.Msg.Tags != null)
            {
                body.Append("System Tags:");
                foreach (string tag in evt.Msg.Tags)
                {
                    body.Append(" "+tag);
                }
            }

            message.text = body.ToString();

            _api.SendMessage(message);
        }
 private static bool HardBounceSentFromPeachtreeDataDomain(WebHookEvent evt)
 {
     return evt.Event == WebHookEventType.Hard_bounce && evt.Msg.Sender.ToLower().Contains("peachtreedata.com");
 }
 private static bool HardBounceOrUnsubscribeFromMailChimpList(WebHookEvent evt)
 {
     var metadata = ParseMetadataFromMandrill(evt);
     return metadata.ContainsKey("MCList") && (evt.Event == WebHookEventType.Hard_bounce || evt.Event == WebHookEventType.Unsub);
 }
 private void UnsubscribeEmailfromMailChimpList(WebHookEvent evt)
 {
     var metadata = ParseMetadataFromMandrill(evt);
     try
     {
         var result = _mailChimpApi.Unsubscribe(metadata["MCList"], new EmailParameter() { Email = evt.Msg.Email }, false, false, false);
     }
     catch (Exception)
     {
     }
 }
        private string GetSendingApplicationName(WebHookEvent evt)
        {
            if (evt.Msg.Tags.Contains("SecureFTP"))
                return "Secure FTP Site";
            if (evt.Msg.Subject.Contains("FAST"))
                return "JobTracker - FAST System";

            return string.Format("Unknown Application. Subject line was: {0}", evt.Msg.Subject);
        }