コード例 #1
0
        public List <Mail> ReceiveMail(Setting setting)
        {
            List <Mail> list = new List <Mail>();

            using (POP3_Client pop3_Client = new POP3_Client())
            {
                //设置SMPT服务地址和端口并连接
                pop3_Client.Connect(setting.SmtpHostName, setting.SmtpPort);
                //设置Authentication
                pop3_Client.Auth(new LumiSoft.Net.AUTH.AUTH_SASL_Client_Login(setting.User.UserName, setting.User.Password));
                if (pop3_Client.Messages != null && pop3_Client.Messages.Count > 0)
                {
                    foreach (POP3_ClientMessage message in pop3_Client.Messages)
                    {
                        //将收到的邮件逐一转化Mail实体类型
                        Mail_Message mail_Message = Mail_Message.ParseFromByte(message.MessageToByte());
                        list.Add(new Mail()
                        {
                            From            = mail_Message.From.ToString(),
                            To              = mail_Message.To.ToArray().Select(address => address.ToString()).ToList(),
                            CreatedDateTime = mail_Message.Date,
                            Subject         = mail_Message.Subject,
                            Body            = mail_Message.BodyHtmlText,
                            Attachments     = mail_Message.Attachments.Select(attach => new Attachment(attach.ContentDisposition.Param_FileName)).ToList()
                        });
                    }
                }
            }
            return(list);
        }