基於LumiSoft.Net.dll發、收、刪郵件

來源:互聯網
上載者:User

標籤: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 copypublic 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 copyprivate 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發、收、刪郵件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.