用过lumisoft.net接收邮件的进来看看

时间:2022-06-01 19:26:02
我用的是从官网下载的最新版的lumisoft.net dll接收邮件,但是出现一个问题,无论是pop3还是imap,只要调试代码就出现问题:“系统检测到在一个调用中尝试使用指针参数时的无效指针地址”,我的DLL版本号是2.0.4492.11923,这个问题貌似只在webform开发下会出现,winform开发无此类问题。如果使用2.0.4029.22109版本的dll就不会出现上述问题,因此我怀疑是不是新版本的lumisoft.net是有问题的DLL,特此来论坛请教

4 个解决方案

#1


这个问题报错是socket的报错,我跟踪了它的源码,也没看出什么破绽,有了解仁兄还请不吝赐教

#2


旧版本的无论webform还是winform都不会在连接服务器的时候出现socket报错(报错代码10014),但是实现收取imap邮件代码过长,非常不好用,所以才决定有新版本的lumisoft

#3


我的源码如下:
#region 同步POP3邮件服务器

        /// <summary>
        /// 同步本地邮件与pop3服务器邮件
        /// </summary>
        /// <param name="server"></param>
        /// <param name="port"></param>
        /// <param name="isSSL"></param>
        /// <param name="username"></param>
        /// <param name="pwd"></param>
        /// <param name="zhbh"></param>
        /// <returns></returns>
        public bool GetPopMailFromServer(string server, int port, bool isSSL, string username, string pwd)
        {
            bool result = false;
            try
            {
                POP3_Client pop = new POP3_Client();
                pop.Connect(server, port, isSSL);
                pop.Authenticate(username, pwd, true);
                if (pop.IsAuthenticated)
                {
                    IList<YJ> mail_list = new List<YJ>();
                    IList<MFJ> attach_list = new List<MFJ>();
                    IList<string> uid_list = dal.QueryUID();
                    POP3_ClientMessageCollection cmc = pop.Messages;

                    foreach (POP3_ClientMessage cm in cmc)
                    {
                        if (!uid_list.Contains(cm.UID))
                        {
                            byte[] bt = cm.MessageToByte();
                            sbyte[] sbt = new sbyte[bt.Length];
                            Buffer.BlockCopy(bt, 0, sbt, 0, bt.Length);
                            string encodeName = IdentifyEncoding.GetEncodingName(sbt).ToLower();//解析编码方式 避免乱码
                            Mail_Message msg = Mail_Message.ParseFromByte(bt, Encoding.GetEncoding(encodeName));
                            //Mail_Message msg = Mail_Message.ParseFromByte(bt);

                            YJ mail = new YJ();
                            mail.FJR = msg.From.ToString();
                            mail.ZT = msg.Subject.ToString();
                            mail.SCSJ = msg.Date;
                            mail.SJR = msg.To.ToString();
                            mail.ZW = msg.BodyHtmlText;
                            mail.MUID = cm.UID;
                            mail.BH = Guid.NewGuid().ToString();

                            if (msg.Attachments.Length > 0)
                            {
                                foreach (MIME_Entity me in msg.Attachments)
                                {
                                    MFJ attach = new MFJ();
                                    //byte[] attachByte = me.ToByte(null, null);
                                    //attach.FJ = attachByte;
                                    string attachpath = System.AppDomain.CurrentDomain.BaseDirectory + "Attachment\\";//路径
                                    string attachname = me.ContentDisposition.Param_FileName;//文件名 含后缀
                                    string totalname = attachpath + attachname;//完全路径
                                    FileInfo fi = new FileInfo(totalname);
                                    if (fi.Exists)
                                    {
                                        string prefix = attachname.Substring(0, attachname.LastIndexOf("."));
                                        string postfix = attachname.Replace(prefix, "");
                                        attachname = prefix + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + postfix;
                                        totalname = attachpath + attachname;
                                    }
                                    File.WriteAllBytes(totalname, ((MIME_b_SinglepartBase)me.Body).Data);

                                    attach.FJMC = attachname;
                                    attach.BH = Guid.NewGuid().ToString();
                                    attach.YJBH = mail.BH;
                                    attach_list.Add(attach);
                                }
                            }
                            mail_list.Add(mail);
                        }
                    }
                    result = dal.InsMail(mail_list, attach_list);
                }
                pop.Disconnect();
                pop.Dispose();
            }
            catch (POP3_ClientException)
            {
                result = false;
                throw;
            }
            return result;
        }

        #endregion

#4


我刚开始看lumisoft.net。不会,帮顶。

#1


这个问题报错是socket的报错,我跟踪了它的源码,也没看出什么破绽,有了解仁兄还请不吝赐教

#2


旧版本的无论webform还是winform都不会在连接服务器的时候出现socket报错(报错代码10014),但是实现收取imap邮件代码过长,非常不好用,所以才决定有新版本的lumisoft

#3


我的源码如下:
#region 同步POP3邮件服务器

        /// <summary>
        /// 同步本地邮件与pop3服务器邮件
        /// </summary>
        /// <param name="server"></param>
        /// <param name="port"></param>
        /// <param name="isSSL"></param>
        /// <param name="username"></param>
        /// <param name="pwd"></param>
        /// <param name="zhbh"></param>
        /// <returns></returns>
        public bool GetPopMailFromServer(string server, int port, bool isSSL, string username, string pwd)
        {
            bool result = false;
            try
            {
                POP3_Client pop = new POP3_Client();
                pop.Connect(server, port, isSSL);
                pop.Authenticate(username, pwd, true);
                if (pop.IsAuthenticated)
                {
                    IList<YJ> mail_list = new List<YJ>();
                    IList<MFJ> attach_list = new List<MFJ>();
                    IList<string> uid_list = dal.QueryUID();
                    POP3_ClientMessageCollection cmc = pop.Messages;

                    foreach (POP3_ClientMessage cm in cmc)
                    {
                        if (!uid_list.Contains(cm.UID))
                        {
                            byte[] bt = cm.MessageToByte();
                            sbyte[] sbt = new sbyte[bt.Length];
                            Buffer.BlockCopy(bt, 0, sbt, 0, bt.Length);
                            string encodeName = IdentifyEncoding.GetEncodingName(sbt).ToLower();//解析编码方式 避免乱码
                            Mail_Message msg = Mail_Message.ParseFromByte(bt, Encoding.GetEncoding(encodeName));
                            //Mail_Message msg = Mail_Message.ParseFromByte(bt);

                            YJ mail = new YJ();
                            mail.FJR = msg.From.ToString();
                            mail.ZT = msg.Subject.ToString();
                            mail.SCSJ = msg.Date;
                            mail.SJR = msg.To.ToString();
                            mail.ZW = msg.BodyHtmlText;
                            mail.MUID = cm.UID;
                            mail.BH = Guid.NewGuid().ToString();

                            if (msg.Attachments.Length > 0)
                            {
                                foreach (MIME_Entity me in msg.Attachments)
                                {
                                    MFJ attach = new MFJ();
                                    //byte[] attachByte = me.ToByte(null, null);
                                    //attach.FJ = attachByte;
                                    string attachpath = System.AppDomain.CurrentDomain.BaseDirectory + "Attachment\\";//路径
                                    string attachname = me.ContentDisposition.Param_FileName;//文件名 含后缀
                                    string totalname = attachpath + attachname;//完全路径
                                    FileInfo fi = new FileInfo(totalname);
                                    if (fi.Exists)
                                    {
                                        string prefix = attachname.Substring(0, attachname.LastIndexOf("."));
                                        string postfix = attachname.Replace(prefix, "");
                                        attachname = prefix + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + postfix;
                                        totalname = attachpath + attachname;
                                    }
                                    File.WriteAllBytes(totalname, ((MIME_b_SinglepartBase)me.Body).Data);

                                    attach.FJMC = attachname;
                                    attach.BH = Guid.NewGuid().ToString();
                                    attach.YJBH = mail.BH;
                                    attach_list.Add(attach);
                                }
                            }
                            mail_list.Add(mail);
                        }
                    }
                    result = dal.InsMail(mail_list, attach_list);
                }
                pop.Disconnect();
                pop.Dispose();
            }
            catch (POP3_ClientException)
            {
                result = false;
                throw;
            }
            return result;
        }

        #endregion

#4


我刚开始看lumisoft.net。不会,帮顶。