zoukankan      html  css  js  c++  java
  • 基于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();  
                        }  
                    }  
                }  
            }  
    

      

  • 相关阅读:
    多数据源报表解析之简单多源报表
    8.5.4 Optimizing InnoDB Redo Logging 优化InnoDB Redo Logging
    8.5.2 Optimizing InnoDB Transaction Management
    8.5.1 Optimizing Storage Layout for InnoDB Tables
    Linux_RHEL7_YUM
    Linux_RHEL7_YUM
    Python基本语法_函数_返回值
    Python基本语法_函数_返回值
    8.4 Optimizing Database Structure 优化数据库结构
    8.3.7 InnoDB and MyISAM Index Statistics Collection InnoDB 和MyISAM 索引统计信息收集
  • 原文地址:https://www.cnblogs.com/amylis_chen/p/6657783.html
Copyright © 2011-2022 走看看