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


    发邮件:

    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();  
                        }  
                    }  
                }  
            }  
    

      

  • 相关阅读:
    Spring security中的BCryptPasswordEncoder方法对密码进行加密与密码匹配
    Eclipse导入SpringBoot项目pom.xml第一行报错Unknown error
    分库分表理论概述
    什么是乐观锁,什么是悲观锁
    oracle中的索引查看
    手动实现tail
    KNN理论
    矩阵以及向量
    numpy常用的几个小函数
    线性回归
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/6657783.html
Copyright © 2020-2023  润新知