예제 #1
0
 public MailHelper(Mail mail)
 {
     Subject = mail.Subject;
     Body = mail.GetBodySnippetAsHtml();
     From = mail.From;
     To = mail.To;
     Date = mail.ReceivedDate.ToShortDateString();
 }
예제 #2
0
        public IEnumerable<Mail> Get()
        {
            var result = new List<Mail>();

            try
            {
                ConnectAndAuthenticate();

                var messageCount = _pop3Client.GetMessageCount();
                for (var i = messageCount; i > 0; i--)
                {
                    var message = _pop3Client.GetMessage(i);
                    var plainText = message.FindFirstPlainTextVersion();
                    var mail = new Mail
                        {
                            Index = i,
                            Id = message.Headers.MessageId ?? message.Headers.Subject + "_" + message.Headers.DateSent,
                            Body = plainText == null ? string.Empty : plainText.GetBodyAsText(),
                            ReceivedDate = message.Headers.DateSent,
                            From = message.Headers.From.Address,
                            To = message.Headers.To.Aggregate("", (seed, recipient) => seed += ", " + recipient.Address).Trim(' ', ','),
                            Subject = message.Headers.Subject
                        };

                    result.Add(mail);
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Unable to fetch mails.", ex);
            }
            finally
            {
                Disconnect();
            }

            return result;
        }