private void MailRecieved(MessageReceived[] messages)
        {
            var supportChannelId = _settingsService.GetSettinngs().SlackSettings.SupportChannelId;

            foreach (var msg in messages)
            {
                var text = string.Format("Support email received FROM: {0} => TO: {1} -- RE: {2}", msg.From, string.Join(",", msg.To), msg.Subject);
                _slackService.Notify(supportChannelId, text + " -- please allow a litle while for Trello to find and process the email.");
            }
        }
        private static void MailRecieved(MessageReceived[] messages)
        {
            var slack = new SlackNotificationService();
            foreach (var msg in messages)
            {
                var text =string.Format("Support email received FROM: {0} => TO: {1} -- RE: {2}", msg.From, string.Join(",", msg.To), msg.Subject);
                Console.WriteLine(text);

                slack.Notify(_supportChannelId, text + " -- please allow a litle while for Trello to find and process the email.");
            }
        }
        public void Post(MessageReceived message)
        {
            Console.WriteLine("");
            Console.WriteLine("writing to Trello board: " + _boardName);
            Console.WriteLine("");

            var builder = new StringBuilder();
            builder.Append("https://api.trello.com/1/lists/");
            builder.Append(_listId + "/cards?key=");
            builder.Append(_trelloKey + "&token=");
            builder.Append(_trelloToken);
            builder.Append(HttpUtility.UrlEncode(string.Format("&name={0}- {1} {2}", message.Subject, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString())));
        }
        private void OnNotificationEvent(object sender, NotificationEventArgs args)
        {
            var messages = new List<MessageReceived>();

            foreach (var argEvent in args.Events)
            {
                var mailReceivedEvent = argEvent as ItemEvent;
                if (mailReceivedEvent == null) continue;
                if (mailReceivedEvent.EventType != EventType.NewMail) continue;

                ServiceResponseCollection<GetItemResponse> items = _service.BindToItems(new[] { mailReceivedEvent.ItemId }, new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients));
                foreach (GetItemResponse item in items)
                {
                    var message = new MessageReceived();

                    message.From = ((EmailAddress)item.Item[EmailMessageSchema.From]).Address;
                    message.To = ((EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray();
                    message.Subject = item.Item.Subject;
                    message.Message = item.Item.Body.ToString();
                    if (item.Item.HasAttachments)
                    {
                        var memStreams = new List<MemoryStream>();
                        foreach (var attachment in item.Item.Attachments.Where(a => a is FileAttachment))
                        {
                            var fileAttachment = attachment as FileAttachment;
                            var ms = new MemoryStream();
                            fileAttachment.Load(ms);

                            memStreams.Add(ms);
                        }

                        message.Attachments = memStreams.ToArray();
                    }

                    //cast it to mail mesage to forward it to trello board
                    var msg = (EmailMessage)item.Item;

                    string messageBodyPrefix = "This message was sent by: " + message.From;
                    ResponseMessage responseMessage = msg.CreateForward();
                    responseMessage.ToRecipients.Add(_trelloForwardingEmailAddress);
                    responseMessage.BodyPrefix = messageBodyPrefix;
                    responseMessage.SendAndSaveCopy();

                    messages.Add(message);
                }
            }

            _callback(messages.ToArray());
        }