0

用于在电子邮件表中插入和在电子邮件收件人表中插入电子邮件 ID 的函数

                public void InsertEmailsFromIMAP(string SelectMailBox, string Server, string AccountId, string Password, int DefaultPort, bool EnableSSL, int EmailFolderId, long EmailAccountId)
                {
                try
                {
                    using (var imap = new AE.Net.Mail.ImapClient(Server, AccountId, Password, AE.Net.Mail.ImapClient.AuthMethods.Login, DefaultPort, EnableSSL))
                    {

                        imap.SelectMailbox(SelectMailBox);
                        MailMessage[] messagetrash = imap.GetMessages(0, 10, false);
                        foreach (MailMessage msgitemtrash in messagetrash)
                        {
                            EmailFolder objEmailfolder = db.EmailFolders.Where(EF => EF.EmailFolderId == EmailFolderId).FirstOrDefault();
                            Email objEmail = new Email();
                            objEmail = GetEmailsData(EmailAccountId, objEmailfolder.EmailFolderId, msgitemtrash.Subject, msgitemtrash.Body, msgitemtrash.Date,  msgitemtrash.From.ToString());
                            db.Emails.AddObject(objEmail);
                            db.SaveChanges();
                            //WriteText("Bcc"+msgitemtrash.Bcc.ToString()+"<br>");
                            //WriteText("Ccc"+msgitemtrash.Cc.ToString()+"<br>");
                            //WriteText("To"+msgitemtrash.To.ToString());

                            long EmailId = objEmail.EmailId;
                            int EmailrecipientType = 0;
                            if (msgitemtrash.To.ToString() != "")
                                EmailrecipientType = 1;
                            else if (msgitemtrash.Bcc.ToString() != "")
                                EmailrecipientType = 2;
                            else if (msgitemtrash.Cc.ToString() != "")
                                EmailrecipientType = 3;
                            WriteText(EmailrecipientType.ToString());
                            WriteText(EmailId.ToString());
                            EmailRecipient objEmailRecipient = new EmailRecipient();
                            objEmailRecipient = GetEmailRecipientData(EmailId,EmailrecipientType );
                            db.EmailRecipients.AddObject(objEmailRecipient);
                            db.SaveChanges();
                        }

                        imap.Dispose();
                    }
                }
                catch(Exception ex)
                {
                    WriteText(ex.ToString());

                }
            }

当在收件人表中插入时,它给出错误 System.Collections.Generic.List。如何转换集合类型以及数据库列名中给出的类型。

4

0 回答 0