C#邮件接收与发送程序

本章节介绍了邮件接收与发送的方法,包括使用LumiSoft.Net库处理IMAP和POP3协议。文章提供了具体的C#代码示例,展示了如何接收邮件、解析邮件内容、处理邮件附件以及发送邮件。此外,还讨论了邮件内容类、附件类和邮件账户信息类的结构。
摘要由CSDN通过智能技术生成

本章节重点介绍邮件接收与发送方法,在文章中存在//注销部分没有拿掉,便于熟悉功能性。

  • 控件说明

控件:LumiSoft.Net 版本号:4.5.6352.37929,System.Net.Mail

  • 程序代码
  1. MailContent.cs
    1. 新建一个类,命名MailContent.cs
    2. 代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;

namespace Helper

{

    public class MailContent

    {

        public bool success { get; set; }

        public string message { get; set; }

        public List<MailSubject> mailSubject { get; set; }

        public int total { get; set; }

       

    }

    public  class MailSubject

    {

        public string Id { get; set; }

        public string MailId { get; set; }

        public string FolderName { get; set; }

        public string Subject { get; set; }

        public List <MailAddressee> From { get; set; }

        public List <MailAddressee> To { get; set; }

        public List<MailAddressee> CC { get; set; }

        public List<MailAddressee> BCC { get; set; }

        public List<MailReceived> Received { get; set; }

        public DateTime InternalDate { get; set; }

        public DateTime Date { get; set; }

        public int Size { get; set; }

        public string Body { get; set; }

        public string MessageID { get; set; } //获取或设置邮件标识符。值null表示未指定。

        public string OriginalMessageID { get; set; }//获取或设置原始邮件标识符。值null表示未指定。

        public string Priority { get; set; }//获取或设置邮件优先级。值null表示未指定。

        public string Parent { get; set; }//获取此实体的父实体,如果这是根实体,则返回null。(继承自MIME_Entity。)。

        public List<MailAttachments> mailAttachments { get; set; }

        public int attachTotal { get; set; }

    }

     

    public class MailAttachments

    {

        public string Id { get; set; }

        public string MailId { get; set; }

        public byte[] Attachment { get; set; }

        public string FileName { get; set; }

        public int Size { get; set; }

    }

    public class MailAddressee

    {

        public string Id { get; set; }

        public string MailId { get; set; }

        

        public string Address { get; set; }

        public string DisplayName { get; set; }

        public string Host { get; set; }

        public string User { get; set; }

        

    }

    public class MailReceived

    {

        public string Id { get; set; }

        public string m_ID { get; set; }

        public string m_Name { get; set; }

        public DateTime m_Time { get; set; }

        public string m_From { get; set; }

    }

    public class MailAccountInfo

    {

            public string Server { get; set; }

            public string ServerName { get; set; }

            public string MailType  { get; set; }

            public int Port { get; set; }

            public bool UseSsl { get; set; }

            public string LoginName { get; set; }

            public string LoginPWD { get; set; }

    }

    

}

  1. FileHelper.cs
    1. 新建一个文件夹,定义为FileHelper.cs
    2. 功能说明:压缩,解压缩,文件到Byte,Byte到文件流,Byte到文件
    3. 代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;

using System.IO.Compression;

namespace  Helper

{

    public abstract class FileHelper

    {

        //压缩字节

        //1.创建压缩的数据流

        //2.设定compressStream为存放被压缩的文件流,并设定为压缩模式

        //3.将需要压缩的字节写到被压缩的文件流

        //FILEEXT  文件格式

        public static byte[] CompressBytes(byte[] InBytes)

        {

            if (InBytes == null) return null;

            using (MemoryStream compressStream = new MemoryStream())

            {

                using (var zipStream = new GZipStream(compressStream, CompressionMode.Compress))

                {

                    zipStream.Write(InBytes, 0, InBytes.Length);

                    zipStream.Close();

                }

                 

                return compressStream.ToArray();

            }

        }

        //解压缩字节

        //1.创建被压缩的数据流

        //2.创建zipStream对象,并传入解压的文件流

        //3.创建目标流

        //4.zipStream拷贝到目标流

        //5.返回目标流输出字节

        public static byte[] DecompressBytes(byte[] InBytes)

        {

            if (InBytes == null) return null;

            using (var compressStream = new MemoryStream(InBytes))

            {

                using (var zipStream = new GZipStream(compressStream, CompressionMode.Decompress))

                {

                    using (var resultStream = new MemoryStream())

                    {

                        zipStream.CopyTo(resultStream);

                        zipStream.Close();

                        return resultStream.ToArray();

                    }

                }

            }

        }

        /// 将 Stream 转成 byte[]

        public static byte[] StreamToBytes(Stream stream,bool Compress=true)

        {

            byte[] bytes = new byte[stream.Length];

            stream.Read(bytes, 0, bytes.Length);

            // 设置当前流的位置为流的开始

            stream.Seek(0, SeekOrigin.Begin);

            if (Compress==true)

            {

                bytes = CompressBytes(bytes);

            }

            return bytes;

        }

        /// 将 byte[] 转成 Stream

        public static Stream BytesToStream(byte[] bytes, bool Decompress=true )

        {

            if (Decompress==true)

           {

                bytes = DecompressBytes(bytes);

            }

            Stream stream = new MemoryStream(bytes);

            return stream;

        }

        public static byte[] FileToByte(string fileName, bool Compress = true)

        {

            // 打开文件

            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);

            // 读取文件的 byte[]

            byte[] bytes = new byte[fileStream.Length];

            fileStream.Read(bytes, 0, bytes.Length);

            fileStream.Close();

            if (Compress==true)

            {

                bytes= CompressBytes(bytes);

            }

            return bytes;

        }

        public static Stream FileToStream(string fileName, bool Compress = true)

        {

            byte[] bytes = FileToByte(fileName, Compress);

            // 把 byte[] 转换成 Stream

            Stream stream = new MemoryStream(bytes);

            return stream;

        }

        public static void ByteToFile(byte[] bytes, string fileName, bool Decompress = true)

        {

            if (Decompress == true)

            {

                bytes = DecompressBytes(bytes);

            }

         //   stream.Read(bytes, 0, bytes.Length);

            // 设置当前流的位置为流的开始

         //   stream.Seek(0, SeekOrigin.Begin);

            // 把 byte[] 写入文件

            FileStream fs = new FileStream(fileName, FileMode.Create);

            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(bytes);

            bw.Close();

            fs.Close();

        }

        public static void StreamToFile(Stream stream, string fileName)

        {

            // 把 Stream 转换成 byte[]

            byte[] bytes = new byte[stream.Length];

            stream.Read(bytes, 0, bytes.Length);

            // 设置当前流的位置为流的开始

            stream.Seek(0, SeekOrigin.Begin);

            // 把 byte[] 写入文件

            ByteToFile(bytes,  fileName,  false);

           

            

        }

    }

}

  1. MailHelper.cs
    1. 新建一个类,命名:MailHelper.cs
    2. 功能接收与发送邮件
    3. 代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using LumiSoft.Net;

using LumiSoft.Net.IMAP;

using LumiSoft.Net.IMAP.Client;

using LumiSoft.Net.Mail;

//using LumiSoft.Net.Mime;

using LumiSoft.Net.MIME;

using LumiSoft.Net.POP3.Client;

using LumiSoft.Net.SMTP;

using LumiSoft.Net.SMTP.Client;

using LumiSoft.Net.AUTH;

using System.Configuration;

using System.IO;

using System.Net.Mail;

using System.Net.Mime;

using System.ComponentModel;

namespace Helper

{

    // public static readonly   int MailPerNum = int.Parse(ConfigurationManager.AppSettings["MailPerNum"].ToString());

    public class MailHelper

    {

        static int mMailPerNum = int.Parse(ConfigurationManager.AppSettings["MailPerNum"].ToString());

        static int mMailNum = 1;

        static string mMailId = string.Empty;

        // static bool mIsReceive = false;

        static string mMailFrom = string.Empty;

        static string mMailTo = string.Empty;

        static string mMailCC = string.Empty;

        static string mMailBCC = string.Empty;

        static int mMessCount = 0;

        static int mMailTotal = 0;

        static int mattachTotal = 0;

        static bool mMailSentSuccess = false;

       

        // static int mAttSize = 0;

        public static MailContent Recive(MailAccountInfo mailAccountInfo)

        {

            MailContent mailContent = new MailContent();

            if (mailAccountInfo.MailType == "POP")

            {

                mailContent = RecivePOP(mailAccountInfo.Server, mailAccountInfo.Port, mailAccountInfo.UseSsl, mailAccountInfo.LoginName, mailAccountInfo.LoginPWD);

            }

            else if (mailAccountInfo.MailType == "IMAP")

            {

                mailContent = ReciveIMAP(mailAccountInfo.Server, mailAccountInfo.Port, mailAccountInfo.UseSsl, mailAccountInfo.LoginName, mailAccountInfo.LoginPWD);

            }

            else

            {

                mailContent.success = false;

                mailContent.message = "MailType类型定义错误!";

                mailContent.total = 0;

            }

            return mailContent;

        }

        private static MailContent RecivePOP(string Server, int PORT, bool UseSsl, string LoginName, string LoginPWD)

        {

            MailContent mailContent = new MailContent();

            List<MailSubject> mailSubject = new List<MailSubject>();

            using (POP3_Client pop3 = new POP3_Client())//2

            {

                #region 账号登陆

                try

                {

                //与Pop3服务器建立连接

                pop3.Connect(Server, PORT, UseSsl);

                //验证身份

                pop3.Login(LoginName, LoginPWD);

                }

                catch (Exception ex)

                {

                    mailContent.success = false;

                    mailContent.message = ex.Message;

                    mailContent.total = 0;

                    //continue;

                    // Helper.WriteLog.Write("POP", ex.Message);

                    //  return ex.Message;

                }

                #endregion

                POP3_ClientMessageCollection messages = pop3.Messages;

                #region 信息循环

                foreach (POP3_ClientMessage ms in messages) //3.0 信息循环

                {

                    mMailId = ms.UID;

                    if (ms != null) //4.0

                    {

                        try

                        {

                            MailSubject rMailSubject = new MailSubject();

                            List<MailAttachments> mailAttachments = new List<MailAttachments>();

                            List<MailAddressee> mailAddressFrom = new List<MailAddressee>();

                            List<MailAddressee> mailAddressTo = new List<MailAddressee>();

                            List<MailAddressee> mailAddressCC = new List<MailAddressee>();

                            List<MailAddressee> mailAddressBCC = new List<MailAddressee>();

                            byte[] messageBytes = ms.MessageToByte();

                            Mail_Message mime_message = Mail_Message.ParseFromByte(messageBytes);

                            #region 邮件附件内容

                            LumiSoft.Net.MIME.MIME_Entity[] attachments = mime_message.GetAttachments(true, true);

                            foreach (LumiSoft.Net.MIME.MIME_Entity _attachment in attachments)

                            {

                                if (_attachment.ContentDisposition != null)

                                {

                                    mattachTotal = 0;

                                    MailAttachments rMailAttachments = new MailAttachments();

                                    string fileName = _attachment.ContentDisposition.Param_FileName;

                                    if (!string.IsNullOrEmpty(fileName))

                                    {

                                        LumiSoft.Net.MIME.MIME_b_SinglepartBase attachmentData = (LumiSoft.Net.MIME.MIME_b_SinglepartBase)_attachment.Body;

                                        rMailAttachments.MailId = mMailId;

                                        rMailAttachments.FileName = fileName;

                                        rMailAttachments.Attachment = attachmentData.Data;

                                        mailAttachments.Add(rMailAttachments);

                                        mattachTotal++;

                                    }

                                }

                                else

                                {

                                    mattachTotal = 0;

                                }

                            }

                            #endregion

                            #region 邮件内容

                            mMailFrom = string.Empty;

                            mMailTo = string.Empty;

                            mMailCC = string.Empty;

                            mMailBCC = string.Empty;

                            if (mime_message.From != null)

                            {

                                MailAddressee rMailAddressFrom = new MailAddressee();

                                foreach (var mFrom in mime_message.From)

                                {

                                    rMailAddressFrom.Address = mFrom.ToString();

                                    /*

                                    if (mMailFrom.Length > 0)

                                    {

                                        mMailFrom = mMailFrom + ",";

                                    }

                                    mMailFrom = mMailFrom + mFrom;

                                    */

                                }

                                mailAddressFrom.Add(rMailAddressFrom);

                            }

                            if (mime_message.To != null)

                            {

                                MailAddressee rMailAddressTo = new MailAddressee();

                                foreach (var mTO in mime_message.To)

                                {

                                    rMailAddressTo.Address = mTO.ToString();

                                    /*

                                    if (mMailTo.Length > 0)

                                    {

                                        mMailTo = mMailTo + ",";

                                    }

                                    mMailTo = mMailTo + mTO;

                                    */

                                }

                                mailAddressTo.Add(rMailAddressTo);

                            }

                            if (mime_message.Cc != null)

                            {

                                MailAddressee rMailAddressCC = new MailAddressee();

                                foreach (var mCC in mime_message.Cc)

                                {

                                    rMailAddressCC.Address = mCC.ToString();

                                    /*

                                    if (mMailCC.Length > 0)

                                    {

                                        mMailCC = mMailCC + ",";

                                    }

                                    mMailCC = mMailCC + mCC;

                                    */

                                }

                                mailAddressCC.Add(rMailAddressCC);

                            }

                            if (mime_message.Bcc != null)

                            {

                                MailAddressee rMailAddressBCC = new MailAddressee();

                                foreach (var mBCC in mime_message.Bcc)

                                {

                                    rMailAddressBCC.Address = mBCC.ToString();

                                    /*

                                    if (mMailBCC.Length > 0)

                                    {

                                        mMailBCC = mMailBCC + ",";

                                    }

                                    */

                                    mMailBCC = mMailBCC + mBCC;

                                }

                                mailAddressBCC.Add(rMailAddressBCC);

                            }

                            rMailSubject.MailId = mMailId;

                            //  rMailSubject.FolderName =  f.FolderName;

                            rMailSubject.From = mailAddressFrom;

                            rMailSubject.To = mailAddressTo;

                            rMailSubject.CC = mailAddressCC;

                            rMailSubject.BCC = mailAddressBCC;

                            rMailSubject.Subject = mime_message.Subject;

                            rMailSubject.InternalDate = mime_message.Date;

                            rMailSubject.Date = mime_message.Date;

                            rMailSubject.Body = mime_message.BodyHtmlText;

                            rMailSubject.mailAttachments = mailAttachments;

                            rMailSubject.attachTotal = mMailTotal;

                            //    mailSubject.Size = email.Rfc822Size;

                            //mailSubject.Size=email.Envelope.

                            mailSubject.Add(rMailSubject);

                            mMailTotal++;

                            #endregion

                        }

                        catch (Exception ex)

                        {

                            //continue;

                            // Helper.WriteLog.Write("POP", ex.Message);

                            //  return ex.Message;

                        }

                    }// 4.0 (ms != null )

                    mailContent.success = true;

                    mailContent.mailSubject = mailSubject;

                    mailContent.total = mMailTotal;

                }//3.0

                #endregion

            }

            return mailContent;

        }

        /*

            Mail_Item类记录邮件的基本信息

            Person类记录的是邮件用户名及名称

            Attachment 类记录附件的基本信息

            Mail_Summary 邮件信息概要类,用于显示邮件列表

            User  用户信息类,记录用户信息

         */

        private static MailContent ReciveIMAP(string Server, int PORT, bool UseSsl, string LoginName, string LoginPWD)

        {//1.0

            MailContent mailContent = new MailContent();

            List<MailSubject> mailSubject = new List<MailSubject>();

            using (IMAP_Client mIMAP = new IMAP_Client())// IMAP

            {//2.0

                #region 账号登陆

                try

                {

                mIMAP.Connect(Server, PORT, UseSsl);

                mIMAP.Login(LoginName, LoginPWD);

                }

                catch (Exception ex)

                {

                    mailContent.success = false;

                    mailContent.message = ex.Message;

                    mailContent.total = 0;

                    //continue;

                    // Helper.WriteLog.Write("POP", ex.Message);

                    //  return ex.Message;

                }

                #endregion

                //2.0  获取文件夹

                #region 获取文件夹

                mIMAP.GetFolders(null).ToList().ForEach(f =>

                {

                    mIMAP.SelectFolder(f.FolderName);

                    var folder = mIMAP.SelectedFolder;

                    mMessCount = folder.MessagesCount;//消息总数,每次至获取mMailNum

                    if (mMessCount > 0 && f.FolderName.IndexOf("-日历-") == -1)

                    {

                        if (mMailPerNum > 1)

                        {

                            mMailNum = mMessCount - mMailPerNum;

                        }

                        if (mMailNum < 0)

                        {

                            mMailNum = 1;

                        }

                        var seqSet = IMAP_t_SeqSet.Parse(mMailNum.ToString() + ":*");//获取mMailNum之后资料,每次是否要获取总数

                        var items = new IMAP_t_Fetch_i[]

                                   {

                                                new IMAP_t_Fetch_i_Envelope(), //邮件的标题、正文等信息

                                                new IMAP_t_Fetch_i_Uid(),

                                                new IMAP_t_Fetch_i_Flags(), //此邮件的标志,应该是已读未读标志

                                                new IMAP_t_Fetch_i_InternalDate(),//貌似是收到的日期

                                                new IMAP_t_Fetch_i_Rfc822()//Rfc822是标准的邮件数据流,可以通过Lumisoft.Net.Mail.Mail_Message对象解析出邮件的所有信息(不确定有没有附件的内容)

                                   };

                        //3.0 获取明细

                        #region 获取明细

                        mIMAP.Fetch(false, seqSet, items, (s, e) =>

                                {

                                    MailSubject rMailSubject = new MailSubject();

                                    List<MailAttachments> mailAttachments = new List<MailAttachments>();

                                    List<MailAddressee> mailAddressFrom = new List<MailAddressee>();

                                    List<MailAddressee> mailAddressTo = new List<MailAddressee>();

                                    List<MailAddressee> mailAddressCC = new List<MailAddressee>();

                                    List<MailAddressee> mailAddressBCC = new List<MailAddressee>();

                                    List <MailReceived> mailReceived = new List<MailReceived>();

                                    #region 开始处理邮件

                                    try //3.1 开始处理邮件

                                    {

                                        var email = e.Value as IMAP_r_u_Fetch;

                                        if (email != null)//3.2

                                        {

                                            mMailId = email.UID.UID.ToString();

                                            mMailTotal++;

                                            //处理正文

                                            #region 处理正文

                                            if (email.Rfc822 != null) //3.5 处理正文

                                            {

                                                email.Rfc822.Stream.Position = 0;

                                                var mine = Mail_Message.ParseFromStream(email.Rfc822.Stream);

                                                email.Rfc822.Stream.Close();

                                               

                                                #region 附件处理

                                                if (mine.Attachments.Count() > 0)

                                                {//3.6 附件处理

                                                    mattachTotal = 0;

                                                    var attlist = mine.Attachments.ToList();

                                                    foreach (var att in attlist)

                                                    {//3.7 清单

                                                        

                                                        var _attachment = att.Body as MIME_b_SinglepartBase;

                                                        string fileName = att.ContentType.Param_Name;

                                                        MailAttachments rMailAttachments = new MailAttachments();

                                                        rMailAttachments.MailId = mMailId;

                                                        rMailAttachments.FileName = fileName;

                                                        rMailAttachments.Attachment = _attachment.Data;

                                                        mailAttachments.Add(rMailAttachments);

                                                        mattachTotal++;

                                                    }

                                                }//3.6 附件处理

                                                else

                                                {

                                                    mattachTotal = 0;

                                                }

                                                #endregion

                                                #region 邮件内容

                                                /*

                                                mMailFrom = string.Empty;

                                                mMailTo = string.Empty;

                                                mMailCC = string.Empty;

                                                mMailBCC = string.Empty;

                                                */

                                                if (email.Envelope.From != null)

                                                {

                                                    MailAddressee rMailAddressFrom = new MailAddressee();

                                                    foreach (var mFrom in email.Envelope.From)

                                                    {

                                                     

                                                        rMailAddressFrom.Address = mFrom.ToString();

                                                        /*

                                                        if (mMailFrom.Length > 0)

                                                        {

                                                            mMailFrom = mMailFrom + ",";

                                                        }

                                                        mMailFrom = mMailFrom + mFrom;

                                                        */

                                                    }

                                                    mailAddressFrom.Add(rMailAddressFrom);

                                                }

                                                if (email.Envelope.To != null)

                                                {

                                                    MailAddressee rMailAddressTo = new MailAddressee();

                                                    foreach (var mTO in email.Envelope.To)

                                                    {

                                                        rMailAddressTo.Address = mTO.ToString();

                                                        /*

                                                        if (mMailTo.Length > 0)

                                                        {

                                                            mMailTo = mMailTo + ",";

                                                        }

                                                        mMailTo = mMailTo + mTO;

                                                        */

                                                    }

                                                    mailAddressTo.Add(rMailAddressTo);

                                                }

                                                if (email.Envelope.Cc != null)

                                                {

                                                    MailAddressee rMailAddressCC = new MailAddressee();

                                                    foreach (var mCC in email.Envelope.Cc)

                                                    {

                                                        rMailAddressCC.Address = mCC.ToString();

                                                        /*

                                                        if (mMailCC.Length > 0)

                                                        {

                                                            mMailCC = mMailCC + ",";

                                                        }

                                                        mMailCC = mMailCC + mCC;

                                                        */

                                                    }

                                                    mailAddressCC.Add(rMailAddressCC);

                                                }

                                                if (email.Envelope.Bcc != null)

                                                {

                                                    MailAddressee rMailAddressBCC = new MailAddressee();

                                                    foreach (var mBCC in email.Envelope.Bcc)

                                                    {

                                                        rMailAddressBCC.Address = mBCC.ToString();

                                                        /*

                                                        if (mMailBCC.Length > 0)

                                                        {

                                                            mMailBCC = mMailBCC + ",";

                                                        }

                                                        */

                                                        mMailBCC = mMailBCC + mBCC;

                                                    }

                                                    mailAddressBCC.Add(rMailAddressBCC);

                                                }

                                                if (mine.Received !=null)

                                                {

                                                    MailReceived rReceived =new MailReceived();

                                                    foreach (var mReceived in mine.Received)

                                                    {

                                                        rReceived.m_Name = mReceived.Name;

                                                        rReceived.m_ID = mReceived.ID;

                                                        rReceived.m_From = mReceived.From;

                                                        rReceived.m_Time = mReceived.Time;

                                                    }

                                                    mailReceived.Add(rReceived);

                                                }

                                                rMailSubject.MailId = mMailId;

                                                rMailSubject.FolderName = f.FolderName;

                                                rMailSubject.From = mailAddressFrom;

                                                rMailSubject.To = mailAddressTo;

                                                rMailSubject.CC = mailAddressCC;

                                                rMailSubject.BCC = mailAddressBCC;

                                                rMailSubject.Subject = email.Envelope.Subject;

                                                rMailSubject.InternalDate = email.InternalDate.Date;

                                                rMailSubject.Date = email.Envelope.Date;

                                                rMailSubject.MessageID=mine.MessageID;

                                                rMailSubject.OriginalMessageID = mine.OriginalMessageID;

                                             //   rMailSubject.Parent = mine.Parent.ToString();

                                                 rMailSubject.Priority = mine.Priority;

                                                rMailSubject.Body = mine.BodyHtmlText;

                                                rMailSubject.mailAttachments = mailAttachments;

                                                rMailSubject.attachTotal = mattachTotal;

                                                rMailSubject.Received = mailReceived;

                                                //    mailSubject.Size = email.Rfc822Size;

                                                //mailSubject.Size=email.Envelope.

                                                mailSubject.Add(rMailSubject);

                                                #endregion

                                            }//3.5 处理正文

                                            #endregion

                                        }

                                        else

                                        {

                                            mMailId = string.Empty;

                                        }

                                    }

                                    catch (Exception ex)//3.1

                                    {

                                        // Console.WriteLine("Handle-Err:" + ex.Message);

                                        mIMAP.Disconnect();

                                        // Helper.WriteLog.Write("IMAP", ex.Message);

                                        // return ex.Message;

                                    }

                                    #endregion

                                });

                        #endregion

                    }

                }

                );//mIMAP.GetFolders(null).ToList().ForEach

            }//2.0 using

            #endregion

            mailContent.success = true;

            mailContent.mailSubject = mailSubject;

            mailContent.total = mMailTotal;

            return mailContent;

        }//1.0

        public static string Send(MailAccountInfo mailAccountInfo, MailSubject mailSubject)

        {

          //  return SendSMTP( mailAccountInfo,  mailSubject);

             return SendSMTP4Lum(mailAccountInfo, mailSubject);

           // return SendSMTP4Mine(mailAccountInfo, mailSubject);

        }

  

            private static string SendSMTP4Lum(MailAccountInfo mailAccountInfo, MailSubject mailSubject)

        {

            string Message = "发送成功!";

            //必须要密码验证

            //SMTP_Client.QuickSendSmartHost(null,mailAccountInfo.Server, mailAccountInfo.Port, mailAccountInfo.UseSsl, mailAccountInfo.LoginName, mailAccountInfo.LoginPWD, mail_Message);

            Mail_Message mail_Message = CreateMessage(mailAccountInfo, mailSubject);

            MemoryStream ms = new MemoryStream();            

            MIME_Encoding_EncodedWord mee = new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8);

            mail_Message.ToStream(ms, mee, Encoding.UTF8);

            mail_Message.Dispose();

            ms.Position = 0;

            //smtp连接

            SMTP_Client smtp_Client = new SMTP_Client();

            smtp_Client.Connect(mailAccountInfo.Server, mailAccountInfo.Port, mailAccountInfo.UseSsl);

            smtp_Client.EhloHelo(mailAccountInfo.Server);

            var auth = new AUTH_SASL_Client_Plain(mailAccountInfo.LoginName, mailAccountInfo.LoginPWD);

            smtp_Client.Auth(auth);

             

            //smtp_Client.Authenticate(mailAccountInfo.LoginName, mailAccountInfo.LoginPWD);

            smtp_Client.MailFrom(mailAccountInfo.LoginName, -1);

            //smtp_Client.SaslAuthMethods;

            if (mailSubject.To != null)

            {

                foreach (var rAddress in mailSubject.To)

                {//多个收件人时循环,单个收件人可省略循环步骤

                    smtp_Client.RcptTo(rAddress.Address);

                }

            }

            

            try

            {

                //发送邮件

                // {"无法访问已释放的对象。\r\n对象名:“ReadLineAsyncOP”。"} System.Exception {System.ObjectDisposedException}

                //有以上错误,但是邮件还是发出去了。(换其他版本没有问题)

               // smtp_Client.SendMessageAsync(ms);

                smtp_Client.SendMessage(ms);

                smtp_Client.Dispose();

            }

            catch (Exception e)

            {

                Message = e.Message;

            }

            finally

            {

                mail_Message.Dispose();

               // smtp_Client.Dispose();

                 mail_Message = null;

                 smtp_Client = null;

            }

           

            return Message;

        }

        private static Mail_Message CreateMessage(MailAccountInfo mailAccountInfo, MailSubject mailSubject)

        {

            Mail_Message mail_Message = new Mail_Message();

            mail_Message.MimeVersion = "1.0";

            mail_Message.MessageID = MIME_Utils.CreateMessageID();

            mail_Message.Date = DateTime.Now;//mailSubject.Date;//DateTime.Now;

            mail_Message.Subject = mailSubject.Subject;

               

            if (mailSubject.From != null)

            {

                mail_Message.From = new Mail_t_MailboxList();

                foreach (var rAddress in mailSubject.From)

                {

                    mail_Message.From.Add(new Mail_t_Mailbox(rAddress.DisplayName, rAddress.Address));

                   

                }

            }

            if (mailSubject.To != null)

            {

                mail_Message.To = new Mail_t_AddressList();

                foreach (var rAddress in mailSubject.To)

                {

                    mail_Message.To.Add(new Mail_t_Mailbox(rAddress.DisplayName, rAddress.Address));

                    

                }

            }

            

            if (mailSubject.BCC != null)

            {

                mail_Message.Bcc = new Mail_t_AddressList();

                foreach (var rAddress in mailSubject.BCC)

                {

                    mail_Message.Bcc.Add(new Mail_t_Mailbox(rAddress.DisplayName, rAddress.Address));

                    

                }

            }

            if (mailSubject.CC != null)

            {

                mail_Message.Cc = new Mail_t_AddressList();

                foreach (var rAddress in mailSubject.CC)

                {

                    mail_Message.Cc.Add(new Mail_t_Mailbox(rAddress.DisplayName, rAddress.Address));

                    

                }

            }

            //设置回执通知

            bool notify = true;

            if (notify)

            {

                mail_Message.DispositionNotificationTo = new Mail_t_MailboxList();

                if (mailSubject.From != null)

                {

                    mail_Message.From = new Mail_t_MailboxList();

                    foreach (var rAddress in mailSubject.From)

                    {

                        mail_Message.DispositionNotificationTo.Add(new Mail_t_Mailbox(rAddress.DisplayName, rAddress.Address));

                        

                    }

                }

                

            }

            #region 定义Body

            /* //--- multipart/mixed -----------------------------------

           MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed);

           contentType_multipartMixed.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');

           MIME_b_MultipartMixed multipartMixed = new MIME_b_MultipartMixed(contentType_multipartMixed);

           mail_Message.Body = multipartMixed;

           //--- multipart/alternative -----------------------------

           MIME_Entity entity_multipartAlternative = new MIME_Entity();

           MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);

           contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');

           MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);

           entity_multipartAlternative.Body = multipartAlternative;

           multipartMixed.BodyParts.Add(entity_multipartAlternative);

           //--- text/plain ----------------------------------------

           MIME_Entity entity_text_plain = new MIME_Entity();

           MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain);

           entity_text_plain.Body = text_plain;

           //普通文本邮件内容,如果对方的收件客户端不支持HTML,这是必需的

           string plainTextBody = "如果你邮件客户端不支持HTML格式,或者你切换到“普通文本”视图,将看到此内容";

           text_plain.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, plainTextBody);

           multipartAlternative.BodyParts.Add(entity_text_plain);

           //--- text/html -----------------------------------------

           string htmlText = mailSubject.Body;//"<html>这是一份测试邮件,<img src=\"cid:test.jpg\">来自<font color=red><b>LumiSoft.Net</b></font></html>";

           MIME_Entity entity_text_html = new MIME_Entity();

           MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html);

           entity_text_html.Body = text_html;

           text_html.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, htmlText);

           multipartAlternative.BodyParts.Add(entity_text_html);

           */

            string htmlText = mailSubject.Body;

            string plainTextBody = "如果你邮件客户端不支持HTML格式,或者你切换到“普通文本”视图,将看到此内容";

            //--- 附件 -------------------------

            if (mailSubject.mailAttachments != null)

            {

                //--- multipart/mixed -------------------------------------------------------------------------------------------------

                MIME_h_ContentType contentType_multipartMixed = new MIME_h_ContentType(MIME_MediaTypes.Multipart.mixed);

                contentType_multipartMixed.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');

                MIME_b_MultipartMixed multipartMixed = new MIME_b_MultipartMixed(contentType_multipartMixed);

                mail_Message.Body = multipartMixed;

                //--- multipart/alternative -----------------------------------------------------------------------------------------

                MIME_Entity entity_mulipart_alternative = new MIME_Entity();

                MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);

                contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');

                MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);

                entity_mulipart_alternative.Body = multipartAlternative;

                multipartMixed.BodyParts.Add(entity_mulipart_alternative);

                //--- text/plain ----------------------------------------------------------------------------------------------------

                // string plainTextBody = "如果你邮件客户端不支持HTML格式,或者你切换到“普通文本”视图,将看到此内容";

                MIME_Entity entity_text_plain = new MIME_Entity();

                MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain);

                entity_text_plain.Body = text_plain;

                text_plain.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, plainTextBody);

                multipartAlternative.BodyParts.Add(entity_text_plain);

                //--- text/html ------------------------------------------------------------------------------------------------------

                MIME_Entity entity_text_html = new MIME_Entity();

                MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html);

                entity_text_html.Body = text_html;

                text_html.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, htmlText);

                multipartAlternative.BodyParts.Add(entity_text_html);

                foreach (var attach in mailSubject.mailAttachments)

                {

                    MemoryStream attachSteam = new MemoryStream(attach.Attachment);

                    string fileName = attach.FileName;

                    MIME_Entity entity_attach = new MIME_Entity();

                    //  entity_attach = Mail_Message.CreateAttachment(attachSteam, fileName);

                    entity_attach = MIME_Message.CreateAttachment(attachSteam, fileName);

                    //multipartMixed.BodyParts.Add(Mail_Message.CreateAttachment(attachSteam, fileName));

                    entity_attach.ContentDisposition = new MIME_h_ContentDisposition(MIME_DispositionTypes.Attachment);

                    entity_attach.ContentDisposition.Param_FileName = fileName;

                    entity_attach.ContentType.Param_Name = fileName;

                    entity_attach.ContentDisposition.Parameters.EncodeRfc2047 = true;

                    entity_attach.ContentType.Parameters.EncodeRfc2047 = true;

                    multipartMixed.BodyParts.Add(entity_attach);

                    //Stream  attachSteam= FileHelper.BytesToStream(attach.Attachment,false);

                    //multipartMixed.BodyParts.Add(Mail_Message.CreateAttachment(attachSteam,attach.FileName));

                    //multipartMixed.BodyParts.Add(MIME_Message.CreateAttachment(attachSteam, attach.FileName));

                }

            }

            else

            {

                //--- multipart/alternative -----------------------------------------------------------------------------------------

                MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative);

                contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.');

                MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative);

                mail_Message.Body = multipartAlternative;

                //--- text/plain ----------------------------------------------------------------------------------------------------

                MIME_Entity entity_text_plain = new MIME_Entity();

                MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain);

                entity_text_plain.Body = text_plain;

                text_plain.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, plainTextBody);

                multipartAlternative.BodyParts.Add(entity_text_plain);

                //--- text/html ------------------------------------------------------------------------------------------------------

                MIME_Entity entity_text_html = new MIME_Entity();

                MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html);

                entity_text_html.Body = text_html;

                text_html.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, htmlText);

                multipartAlternative.BodyParts.Add(entity_text_html);

            }

            /*

             * //嵌入图片

            foreach (string imageFile in mailInfo.EmbedImages)

            {

                MIME_Entity entity_image = new MIME_Entity();

                entity_image.ContentDisposition = new MIME_h_ContentDisposition(MIME_DispositionTypes.Inline);

                string fileName = DirectoryUtil.GetFileName(imageFile, true);

                entity_image.ContentID = BytesTools.BytesToHex(Encoding.Default.GetBytes(fileName));

                MIME_b_Image body_image = new MIME_b_Image(MIME_MediaTypes.Image.jpeg);

                entity_image.Body = body_image;

                body_image.SetDataFromFile(imageFile, MIME_TransferEncodings.Base64);

                multipartMixed.BodyParts.Add(entity_image);

            }

            */

            #endregion

            return mail_Message;

        }

        private static string SendSMTP(MailAccountInfo mailAccountInfo, MailSubject mailSubject)

        {

            string Message = string.Empty;

            MailMessage mailMessage = new MailMessage();

            mailMessage.BodyEncoding = System.Text.Encoding.Default;//设置正文的编码形式.这里的设置为取系统默认编码--System.Text.Encoding.Default

                                                                    //邮件传送通知选项

            mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

            mailMessage.IsBodyHtml = true;

            //设置邮件的优先级为正常

            mailMessage.Priority = MailPriority.Normal;

            //设置主题的编码形式.这里的设置为取系统默认编码

            mailMessage.SubjectEncoding = System.Text.Encoding.Default;// System.Text.Encoding.Default;

            mailMessage.Subject = mailSubject.Subject;

            mailMessage.Body = mailSubject.Body;

            if (mailSubject.From != null)

            {

                foreach (var rAddress in mailSubject.From)

                {

                   

                     mailMessage.From = new MailAddress(rAddress.Address,rAddress.DisplayName);

                     mailMessage.Sender = new MailAddress(rAddress.Address, rAddress.DisplayName);

                }

            }

            if (mailSubject.To != null)

            {

                foreach (var rAddress in mailSubject.To)

                {

                    

                    mailMessage.To.Add(new MailAddress(rAddress.Address, rAddress.DisplayName));

                   

                }

            }

            if (mailSubject.CC != null)

            {

                foreach (var rAddress in mailSubject.CC)

                {

                    mailMessage.CC.Add(new MailAddress(rAddress.Address, rAddress.DisplayName));

                }

            }

            if (mailSubject.BCC != null)

            {

                foreach (var rAddress in mailSubject.BCC)

                {

                    mailMessage.Bcc.Add(new MailAddress(rAddress.Address, rAddress.DisplayName));

                }

            }

             

            if(mailSubject.mailAttachments !=null)

            {

                foreach (var rAttachments in mailSubject.mailAttachments)

                {

                    Stream docStream = new MemoryStream(rAttachments.Attachment);

                    Attachment attachment = new Attachment(docStream, rAttachments.FileName, MediaTypeNames.Text.Plain);

                    mailMessage.Attachments.Add(attachment);

                    // content.

                }

            }

            ;

            SmtpClient smtpClient = new SmtpClient();

            smtpClient.Host = mailAccountInfo.Server;//通过Host属性来设置SMTP 主机服务器            

            smtpClient.Port = mailAccountInfo.Port;

            smtpClient.UseDefaultCredentials = true;//false  false,则连接到服务器时会将 Credentials 属性中设置的值用作凭据。如果 UseDefaultCredentials 属性设置为 false 并且尚未设置 Credentials 属性,则将邮件以匿名方式发送到服务器。UseDefaultCredentials 的默认值为false。

            smtpClient.EnableSsl = mailAccountInfo.UseSsl;

            // true;  UseSsl =true,Port 465,发送出现 无法从传输连接中读取数据: net_io_connectionclosed,据说465端口不能用。

            //   smtpClient.ServicePoint.MaxIdleTime = 60000;

               smtpClient.Timeout = 60000;

            /*

            if (smtpClient.DeliveryMethod == SmtpDeliveryMethod.SpecifiedPickupDirectory && smtpClient.PickupDirectoryLocation.StartsWith("~"))

            {

                string root = AppDomain.CurrentDomain.BaseDirectory;

                string pickupRoot = smtpClient.PickupDirectoryLocation.Replace("~/", root);

                pickupRoot = pickupRoot.Replace("/", @"\");

                smtpClient.PickupDirectoryLocation = pickupRoot; //获取或设置文件夹,应用程序在该文件夹中保存将由本地 SMTP 服务器处理的邮件。

            }

            */

            //smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

            

         

            通過遠程SMTP服務器傳送該郵件,這裡的network表示你要使用的远程SMTP服務器。

             smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

             

           // smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis;

            //通過本機SMTP服務器傳送該郵件,这里的PickupDirectoryFromIis表示你的邮件会通过本机IIS的SMTP服務器传送你的邮件。所以如果使用该项一定要设定在SMTP服務器上设定好你要转到的服务器的地址。下文会详细介绍。

            //smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;

            //表示电子邮件会被复制到System.Net.Mail.SmtpDeliveryMethod.PickupDirectorylocation所指定的目录中。以便有其他程序来执行发送该邮件。

              

            try

            {

                smtpClient.Credentials = new System.Net.NetworkCredential(mailAccountInfo.LoginName, mailAccountInfo.LoginPWD);

                //smtpClient.SendAsync(mailMessage, "userToken");

                 

               smtpClient.Send(mailMessage);

               //  smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);

               // smtpClient.SendAsync(mailMessage, "true");//异步发送邮件,如果回调方法中参数不为"true"则表示发送失败

            }

            catch (Exception e)

            {

                Message = e.Message;

            }

            /*

            smtpClient.SendCompleted += new

               SendCompletedEventHandler(SendCompletedCallback);

            

            try

            {

                smtpClient.SendAsync(mailMessage, "true");//异步发送邮件,如果回调方法中参数不为"true"则表示发送失败

            }

            catch (Exception e)

            {

                Message=e.Message;

                ;

            }

            */

            finally

            {

                mailMessage.Dispose();

                smtpClient.Dispose();

               // mailMessage = null;

               // smtpClient = null;

            }

            return "";

        }

        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

        {

            string Message = (string)e.UserState;

            //string message = string.Empty;

            if (e.Cancelled)

            {

                //Console.WriteLine("取消发送" + token);

                mMailSentSuccess = false;

                Message = "异步操作取消";

            }

            if (e.Error != null)

            {

                //Console.WriteLine(e.Error.ToString());

                mMailSentSuccess = false;

                Message = (string.Format("userstate:{0},message:{1}", (string)e.UserState, e.Error.ToString()));

            }

            else

            {

                mMailSentSuccess = true;

                //message = (string)e.userstate;

                //执行回调方法

                

            }

            

        }

        

    }

     

}

  1. 其中
  • 测试案例
  1. IMAP测试方式(接收邮件)

            MailAccountInfo mailAccountInfo = new MailAccountInfo();

            MailContent mailContent = new MailContent();

            mailAccountInfo.Server = "IMAP服务器";

            mailAccountInfo.MailType = "IMAP";

            mailAccountInfo.UseSsl = true;//Ssl是否勾选,勾选与不勾选端口不同

            mailAccountInfo.Port = 993;//端口

            mailAccountInfo.LoginName = "邮箱账号含@后面";

            mailAccountInfo.LoginPWD = "邮箱密码";

            mailContent=MailHelper.Recive(mailAccountInfo);

  1. POP测试方式(接收邮件)

            MailAccountInfo mailAccountInfo = new MailAccountInfo();

            MailContent mailContent = new MailContent();    

mailAccountInfo.Server = "pop服务器";

            mailAccountInfo.MailType = "POP";

            mailAccountInfo.UseSsl = true;//Ssl是否勾选,勾选与不勾选端口不同

            mailAccountInfo.Port = 995;//端口

            mailAccountInfo.LoginName = "邮箱账号含@后面";

            mailAccountInfo.LoginPWD = "邮箱密码";

            mailContent = MailHelper.Recive(mailAccountInfo);

  1. SMTP测试方式(发送邮件)

            MailSubject mailSubject=new MailSubject();

            MailAddressee mailAddressForm =new MailAddressee();

            MailAddressee mailAddressTo = new MailAddressee();

            MailAttachments mailAttachments = new MailAttachments();

            MailAccountInfo mailAccountInfo = new MailAccountInfo();

            List<MailAddressee> mailAddressFormList = new List<MailAddressee>();

            List<MailAddressee> mailAddressToList = new List<MailAddressee>();

            List<MailAttachments> mailAttachmentsList = new List<MailAttachments>();

            mailAccountInfo.Server = "SMTP服务器";

            mailAccountInfo.ServerName = "服务器名称";

            mailAccountInfo.MailType = "SMTP";

            mailAccountInfo.UseSsl = false;// false;// true;  UseSsl =true,Port 465,发送出现 无法从传输连接中读取数据: net_io_connectionclosed,据说465端口不能用。

            mailAccountInfo.Port = 25;//25;//465;587

            mailAccountInfo.LoginName = "邮箱账号含@后面";

            mailAccountInfo.LoginPWD = "密码";

           mailSubject.Date = DateTime.Now ;

            mailSubject.Subject = "测试案例";

            mailSubject.Body = webBrowser1.DocumentText;//Body内容HTML格式(此处请调整)

            mailAddressForm.Address = "发信人邮箱";//XXX@163.com

            mailAddressForm.DisplayName = "report";//测试账号

            mailAddressFormList.Add(mailAddressForm);

            mailSubject.From = mailAddressFormList;

            mailAddressTo.Address = "收信人邮箱";

            mailAddressTo.DisplayName = "收信人名称";

            mailAddressToList.Add(mailAddressTo);

            mailAddressTo.Address = "收信人邮箱";

            mailAddressTo.DisplayName = "收信人名称";

            mailAddressToList.Add(mailAddressTo);

            mailSubject.To= mailAddressToList;

          //附件测试(用一个文件做两个附件)

            string path2 = System.Environment.CurrentDirectory;

            path2 = path2 + "\\DOC\\abc.1.txt";

            int FileTxtIndex = path2.LastIndexOf(".");

            string FileTxt = path2.Substring(FileTxtIndex + 1, path2.Length - (FileTxtIndex + 1));

            byte[] FileByte = FileHelper.FileToByte(path2, false);

            mailAttachments.Attachment = FileByte;

            mailAttachments.FileName = "abc.1.txt";

            mailAttachmentsList.Add(mailAttachments);

            mailAttachments.Attachment = FileByte;

            mailAttachments.FileName = "abc.1.txt";

            mailAttachmentsList.Add(mailAttachments);

            mailSubject.mailAttachments=mailAttachmentsList;

            string Message = MailHelper.Send(mailAccountInfo, mailSubject);

  • 主要功能与问题点介绍
  1. 附件为何用byte保存?==>此部分将保存数据库中,MSSQL数据库栏位定义:image.

若需要把byte变为File文件,请用FileHelper.ByteToFile来转换,参数 Decompress = false(若byte没有压缩用False,压缩用true)

文档保存案例:

           string path4 = System.Environment.CurrentDirectory;

            path4 = path4 + "\\DOC\\abc.2.txt";

            FileHelper.ByteToFile(Byte, path4, False);

  1. CompressBytes/DecompressBytes作用是什么?==>Byte压缩与解压缩,后续规划: 规划附件保存数据库前先压缩,待在UI下载、展示、作为附件发送的时将进行解压。
  2. 接收IMAP与POP二种模式,根据需要进行决定,POP只能全部接收,不能部分接收。
  3.  static int mMailPerNum = int.Parse(ConfigurationManager.AppSettings["MailPerNum"].ToString());作用:针对IMAP有效,每次每个文件夹收多少份邮件,此不跟需要在app.config进行配置

  <appSettings>

    <!--邮件笔-->

    <add key="MailPerNum" value="5"/>    

  </appSettings>

  1. 发送写了两个:SendSMTP、SendSMTP4Lum,其中SendSMTP是用VS的System.Net.Mail发送,测试问题点:465端口无法发送;SendSMTP4Lum使用LumiSoft.Net进行发送。建议使用SendSMTP4Lum。
  2. SendSMTP:有异步发送,若需要使用把注销部分取消,但是实际测试主旨乱码待解。
  3. SendSMTP:匿名发送,把UseDefaultCredentials=false即可。
  4. SendSMTP4Lum:回执通知是否需要使用,请按需定义。
  5. 不管SendSMTP、SendSMTP4Lum在服务器上,无法找到已发送邮件,即未同步已发送邮箱待解。
  6. LumiSoft.Net最新版本4.7.8187.33884在发送时候出现{"无法访问已释放的对象。\r\n对象名:“ReadLineAsyncOP”。"},但是邮件也发送出去,使用4.5.6352.37929与2.0.4492.11923版本该问题不存在。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值