码迷,mamicode.com
首页 > Web开发 > 详细

基于LumiSoft.Net.dll发、收、删邮件

时间:2017-04-02 00:12:36      阅读:764      评论:0      收藏:0      [点我收藏+]

标签:smtp   create   tin   attach   string   use   word   str   got   

发邮件:

using LumiSoft.Net.SMTP.Client;  
  
  
Mime m = new Mime();  
MimeEntity mainEntity = m.MainEntity;  
// Force to create From: header field  
mainEntity.From = new AddressList();  
mainEntity.From.Add(new MailboxAddress(txtFrom.Text, txtFrom.Text));  
 // Force to create To: header field  
 mainEntity.To = new AddressList();  
 mainEntity.To.Add(new MailboxAddress(txtTo.Text, txtTo.Text));  
mainEntity.Subject = txtSubject.Text;  
//添加正文  
mainEntity.ContentType = MediaType_enum.Multipart_mixed;  
MimeEntity textEntity = mainEntity.ChildEntities.Add();  
textEntity.ContentType = MediaType_enum.Text_html;  
textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;  
textEntity.DataText = txtBody.Text;  
//发送附件  
  MimeEntity attachmentEntity = new MimeEntity();  
  attachmentEntity.ContentType = MediaType_enum.Application_octet_stream;  
  attachmentEntity.ContentDisposition = ContentDisposition_enum.Attachment;  
  attachmentEntity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;  
  attachmentEntity.ContentDisposition_FileName = "c:/test.jpg";  
  attachmentEntity.DataFromFile("c:/test.jpg");  
      
  mainEntity.ChildEntities.Add(attachmentEntity);  
      
  SMTP_Client.QuickSend(m);  

  收邮件:

using LumiSoft.Net.POP3.Client;  
using LumiSoft.Net;  
using LumiSoft.Net.Mime;  
[csharp] view plain copy
public List<Mime> GetEmails(string pop3Server, string pop3Port, string username, string password)  
        {  
            bool pop3UseSsl = false;  
            List<string> gotEmailIds = new List<string>();  
            List<Mime> result = new List<Mime>();  
            using (POP3_Client pop3 = new POP3_Client())  
            {  
                try  
                {  
                    pop3.Connect(pop3Server, Convert.ToInt32(pop3Port), pop3UseSsl);  
                    pop3.Authenticate(username, password, false);  
                    POP3_ClientMessageCollection infos = pop3.Messages;  
                    foreach (POP3_ClientMessage info in infos)  
                    {  
                        if (gotEmailIds.Contains(info.UID))  
                            continue;  
                        byte[] bytes = info.MessageToByte();  
                        gotEmailIds.Add(info.UID);  
                        Mime mime = Mime.Parse(bytes);  
                        result.Add(mime);  
                    }  
                }  
                catch (Exception ex)  
                {  
                    throw new Exception(ex.Message);  
                }  
            }  
            return result;  
        }  

  删除邮件:

using LumiSoft.Net.POP3.Client;  
using LumiSoft.Net;  
using LumiSoft.Net.Mime;  
[csharp] view plain copy
private void DeleteMail()  
        {  
            using (POP3_Client c = new POP3_Client())  
            {  
                c.Connect(pop3Server, Convert.ToInt32(pop3Port));  
                c.Authenticate(username, password, false);  
                if (c.Messages.Count > 0)  
                {  
                    foreach (POP3_ClientMessage mail in c.Messages)  
                    {  
                        mail.MarkForDeletion();  
                    }  
                }  
            }  
        }  

  

基于LumiSoft.Net.dll发、收、删邮件

标签:smtp   create   tin   attach   string   use   word   str   got   

原文地址:http://www.cnblogs.com/amylis_chen/p/6657783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!