基于LumiSoft.Net.dll发、收、删邮件
Net 基于 邮件 dll
2023-09-14 09:00:19 时间
发邮件:
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(); } } } }
相关文章
- 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到Ubuntu 16.04
- C#.Net实体代码生成工具(EntitysCodeGenerate)的使用及.NET中的ORM实现
- .NET Core基于SQL Server数据库主从同步实现读写分离实战演练
- .NET基于Eleasticsearch搭建日志系统实战演练
- .NET 开源Protobuf-net从入门到精通
- ASP.NET中Get和Post的用法
- 《ASP.NET MVC4 WEB编程》学习笔记------.net mvc实现原理ActionResult/View
- C#.NET常见问题(FAQ)-如何改变字符串编码
- Asp.Net Web API 2第十七课——Creating an OData Endpoint in ASP.NET Web API 2(OData终结点)
- asp.net中Repeater控件用法笔记
- 重新整理 .net core 实践篇 ———— linux 上线篇 [外篇]
- 重新整理 .net core 实践篇—————配置系统之简单配置中心[十一]
- .NET中的六个重要概念:栈、堆、值类型、引用类型、装箱和拆箱
- ASP.NET Core 6框架揭秘实例演示[20]:“数据保护”框架基于文件的密钥存储
- 从执行上下文角度重新理解.NET(Core)的多线程编程[1]:基于调用链的”参数”传递
- [ASP.NET Core 3框架揭秘] 文件系统[1]:抽象的“文件系统”
- 【原创】开源Math.NET基础数学类库使用(10)C#进行基本数据统计
- paip.java c# .net php python调用c++ c dll so windows api 总结
- accusoft.SmartZone OCR / ICR for net Crack
- Visioforge.NET SDK视频播放,视频捕捉,视频编辑,视频加密
- Spire.Office 7.4.5 for .NET
- ASP.NET Core 中的基于角色的授权ASP.NET Core 中的基于角色的授权
- IronXL for .NET 2022.6
- 【.Net实用方法总结】 整理并总结.NET 中的 System.IO.Pipelines(管道)
- ASP.NET给图片加水印——上传文件