Ejemplo n.º 1
0
        public void Execute(MailboxConnectionInfo mailboxInfo)
        {
            Console.WriteLine("Replying to all email from {0}:{1}", mailboxInfo.ReceiveHostName, mailboxInfo.ReceivePort);

            _retriever.GetMessages(mailboxInfo, e => HandleMessage(e, mailboxInfo));

            Console.WriteLine("Done.");
        }
        public void Execute(MailboxConnectionInfo mailboxInfo)
        {
            Console.WriteLine("Retrieving emails from {0} at {1}:{2}", mailboxInfo.Username, mailboxInfo.ReceiveHostName, mailboxInfo.ReceivePort);

            _retriever.GetMessages(mailboxInfo, HandleMessage);

            Console.WriteLine();
            Console.WriteLine("Done.");
        }
Ejemplo n.º 3
0
        public void Execute(MailboxConnectionInfo mailboxInfo)
        {
            Console.WriteLine("Retrieving email from {0}:{1}", mailboxInfo.ReceiveHostName, mailboxInfo.ReceivePort);

            _retriever.GetMessages(mailboxInfo, message =>
            {
                Console.WriteLine("- From: {0}, Subject: {1}", message.From.ToString(), message.Subject);
                return false;
            });

            Console.WriteLine("Done.");
        }
Ejemplo n.º 4
0
        private bool HandleMessage(IReceivedEmail email, MailboxConnectionInfo mailboxInfo)
        {
            Console.Write("- Sending email to {0}...", email.From.ToString());

            EmailBuilder response = BuildResponse(email);
            _sender.SendEmail(mailboxInfo, response);

            Console.WriteLine(" Done");

            // pretend we failed so that we don't delete any emails
            return false;
        }
Ejemplo n.º 5
0
        public void SendEmail(MailboxConnectionInfo mailbox, EmailBuilder message)
        {
            using (SmtpClient client = new SmtpClient())
            {
                // configure the smtp client
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Host = mailbox.SmtpHostName;
                client.Port = mailbox.SmtpPort;

                if (mailbox.SmtpRequiresAuthentication)
                {
                    client.Credentials = new System.Net.NetworkCredential(mailbox.Username, mailbox.Password);
                }

                // send the email
                MailMessage mailMessage = ConvertEmail(message);

                mailMessage.From = ConvertEmailAddress(mailbox.EmailAddress);

                client.Send(mailMessage);
            }
        }
Ejemplo n.º 6
0
        private static MailboxConnectionInfo GetMailboxInfoFromAppConfig()
        {
            MailboxConnectionInfo mailboxInfo = new MailboxConnectionInfo()
            {
                Username = ConfigurationManager.AppSettings["Username"],
                Password = ConfigurationManager.AppSettings["Password"],
                SmtpRequiresAuthentication = Boolean.Parse(ConfigurationManager.AppSettings["SmtpRequiresAuthentication"]),
            };

            mailboxInfo.EmailAddress = new EmailAddress(
                ConfigurationManager.AppSettings["EmailAddress"],
                ConfigurationManager.AppSettings["EmailName"]);

            // pop3 server
            string pop3Server = ConfigurationManager.AppSettings["Pop3Server"];
            if (String.IsNullOrEmpty(pop3Server))
                throw new ApplicationException("You must specify a POP3 server");

            string pop3Host;
            int pop3Port;
            ParseServerName(pop3Server, out pop3Host, out pop3Port, mailboxInfo.ReceivePort);
            mailboxInfo.ReceiveHostName = pop3Host;
            mailboxInfo.ReceivePort = pop3Port;

            // smtp server
            string smtpServer = ConfigurationManager.AppSettings["SmtpServer"];
            if (String.IsNullOrEmpty(smtpServer))
                throw new ApplicationException("You must specify an SMTP server");

            string smtpHost;
            int smtpPort;
            ParseServerName(smtpServer, out smtpHost, out smtpPort, mailboxInfo.SmtpPort);
            mailboxInfo.SmtpHostName = smtpHost;
            mailboxInfo.SmtpPort = smtpPort;

            return mailboxInfo;
        }