最近在用 LumiSoft  进行邮件读取,然后操作相关附件
邮件使用的是qq邮箱,读取后进行移除,但是怎么都移除不了 后来咨询了官方客服,
原来是设置不对 需要 取消掉 X禁止收信软件删信 (仅对 POP3 协议有效。为什么会有收信软件删信?)

-----另外附上我写的相关代码

using LumiSoft.Net.Log;
using LumiSoft.Net.Mail;
using LumiSoft.Net.MIME;
using LumiSoft.Net.POP3.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Net;
using System.Text;
using System.Linq; namespace MCP.Sync.MailAttachCenter
{
public class MailAttachCenterBiz
{
// const string smtp = "imap.exmail.qq.com";
const string smtp = "pop.exmail.qq.com"; const int smtpport = 995;
const string user = "";
const string pwd = "";
const string dirfolder = @"D:\email\";
const string FileServerUrl = ""; const string module = "module_Sys_MailAttachCenter";
const string folderId = "folderId_Sys_MailAttachCenter"; public void SyncMail(ref string returnMessage)
{ using (POP3_Client pop3 = new POP3_Client())
{
//这里面存在无法删除邮件,所以导致只能通过去重的方式来处理重复读取的问题 var attachList =new List<MailAttach>();
using (var db=new MCPERP_MailAttachEntities())
{ attachList = db.Sys_MailAttachCenter.Select(s => new MailAttach { MUID=s.MUID}).ToList(); } pop3.Connect(smtp, smtpport, true);
pop3.Login(user, pwd);//两个参数,前者为Email的账号,后者为Email的密码
pop3.Logger = new Logger();
pop3.Logger.WriteLog += new EventHandler<WriteLogEventArgs>(WriteLog); POP3_ClientMessageCollection messages = pop3.Messages; for (int i = 0; i < messages.Count; i++)
{
var mEntity = new Sys_MailAttachCenter();
mEntity.SMTPServerName = smtp; Dictionary<string, string> dic_file = new Dictionary<string, string>(); POP3_ClientMessage message = messages[i];//转化为POP3 if (attachList.Find(x=>x.MUID==message.UID)!=null)
{
continue; } pop3.Logger.AddText("\r\n正在检查第{0}封邮件..."+ i + 1);
if (message != null)
{
mEntity.MUID = message.UID; byte[] messageBytes = message.MessageToByte();
if (messageBytes != null && messageBytes.Length > 0)
{ Mail_Message mime_message = Mail_Message.ParseFromByte(messageBytes);
Mail_Message mime_header = Mail_Message.ParseFromByte(message.HeaderToByte());
if (mime_header != null)
{
mEntity.Subject =!string.IsNullOrEmpty( mime_header.Subject)? mime_header.Subject.Trim():string.Empty;
mEntity.SendDT = mime_header.Date;
//区分抄送人
if (mime_header.Cc != null)
{
StringBuilder sb = new StringBuilder();
foreach (Mail_t_Mailbox recipient in mime_header.Cc.Mailboxes)
{
string displayname = recipient.DisplayName;
string address = recipient.Address; sb.AppendFormat("{0};", address); }
mEntity.CC = sb.ToString().Trim(';');
} if (mime_header.From != null)
{
StringBuilder sb = new StringBuilder();
StringBuilder sb_sender = new StringBuilder();
foreach (Mail_t_Mailbox recipient in mime_header.From)
{
string displayname = recipient.DisplayName;
string address = recipient.Address; sb.AppendFormat("{0};", address);
sb_sender.AppendFormat("{0};", displayname); }
mEntity.Sender = sb_sender.ToString().Trim(';');
mEntity.FromMail = sb.ToString().Trim(';');
} if (mime_header.To != null)
{
StringBuilder sb = new StringBuilder();
foreach (Mail_t_Mailbox recipient in mime_header.To.Mailboxes)
{
string displayname = recipient.DisplayName;
string address = recipient.Address; sb.AppendFormat("{0};", address); }
mEntity.ToMail = sb.ToString().Trim(';');
}
} var body = mime_message.BodyText;
if (body != null)
{
mEntity.Body = body.Length > 1000 ? "超长被截断--"+body.Substring(0,990) : body;
} //保存邮件的整体附件
DirectoryInfo dir = new DirectoryInfo(dirfolder);
if (!dir.Exists) dir.Create(); string emailPath = dirfolder + message.UID + ".eml";
File.WriteAllBytes(emailPath, messageBytes);
dic_file.Add(Guid.NewGuid().ToString(), emailPath); //附件处理
MIME_Entity[] attachments = mime_message.GetAttachments(true, true);
mEntity.AttachmentsCount = 1;
if (attachments != null && attachments.Length > 0)
{
mEntity.AttachmentsCount = mEntity.AttachmentsCount+attachments.Length;
foreach (MIME_Entity entity in attachments)
{
if (entity.ContentDisposition != null)
{
string fileName = entity.ContentDisposition.Param_FileName;
if (!string.IsNullOrEmpty(fileName))
{
var dirFileName = GetValidName(message.UID + fileName);
string path = Path.Combine(dir.FullName, dirFileName);
MIME_b_SinglepartBase byteObj = (MIME_b_SinglepartBase)entity.Body;
Stream decodedDataStream = byteObj.GetDataStream();
using (FileStream fs = new FileStream(path, FileMode.Create))
{
LumiSoft.Net.Net_Utils.StreamCopy(decodedDataStream, fs, 4000);
}
dic_file.Add(Guid.NewGuid().ToString(), path); //这里实现上传附件
//上传成功以后删除本地缓存的附件 pop3.Logger.AddText($"{fileName}已经被下载。");
}
}
}
}
} var result = SaveFileToServer(dic_file, mEntity);//保存文件方法
if (result)
{
message.MarkForDeletion();//移除这个邮件
}
}
}
}
} public static string GetValidName(string fileName)
{
foreach (char c in System.IO.Path.GetInvalidFileNameChars())
{
fileName = fileName.Replace(c, ' ');
}
return fileName;
}
private void WriteLog(object sender, WriteLogEventArgs e)
{
if (e!=null && e.LogEntry!=null)
{ }
} /// <summary>
/// 保存附件到文件服务器并添加到
/// </summary>
/// <returns></returns>
private bool SaveFileToServer(Dictionary<string,string> dir, Sys_MailAttachCenter mEntity)
{
try
{
if (mEntity!=null && dir.Count>0)
{ var fList = new List<Sys_FileInfo>(); foreach (var item in dir)
{ string address = FileServerUrl + string.Format("Home/UploadFile?module={0}&folderId={1}&uploadDate={2}", module, folderId, DateTime.Now.ToString("yyyyMMdd"));
var buffer = new WebClient().UploadFile(address, "post", item.Value);
string result = Encoding.UTF8.GetString(buffer);
var fileServerPath = FileServerUrl + result.Replace("~/", "");
//判断文件是不是存在 清空临时存储的文件
if (System.IO.File.Exists(item.Value))
{
System.IO.File.Delete(item.Value);
} Sys_FileInfo file = new Sys_FileInfo();
file.CreateDT = DateTime.Now;
file.CreaterName = module;
file.Description ="邮件附件处理中心创建";
file.FileType = Path.GetExtension(item.Value);
file.folderId = folderId;
file.module = module;
file.FileJobno = mEntity.MUID.ToString();
file.FileId = Guid.NewGuid().ToString("N");
file.EnabledMark = 1;
file.DeleteMark = 0;
file.FilePath = fileServerPath;
file.FileName = Path.GetFileName(item.Value);
file.FileExtensions = Path.GetExtension(item.Value);
fList.Add(file); } using (var db = new MCPERP_MailAttachEntities())
{ db.Sys_FileInfo.AddRange(fList);
mEntity.CreateDT = DateTime.Now;
mEntity.IsRead = false;
mEntity.IsReply = false;
db.Sys_MailAttachCenter.Add(mEntity);
db.SaveChanges();
}
return true;
} return false;
}
catch (Exception ex)
{ throw ex;
}
}... }
public class MailAttach
{
public string MUID { get; set; }
}
}

  

LumiSoft 邮件操作删除(无法删除解决方法)的更多相关文章

  1. ECSHOP后台登陆后一段时间不操作就超时的解决方法

    ECSHOP后台登陆后一段时间不操作就超时的解决方法 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2012-05-27   客户生意比较好,因此比较忙,常常不在电脑前 ...

  2. 无法删除DLL文件解决方法(转)

    手动解决dll文件无法删除的终极方法 手动解决dll文件无法删除的终极方法 相信大家都遇见过:在删除一些软件的时候弹出某某文件正在运行或磁盘写保护不能删除这样的报错提示吧.而常常删除不掉的都一些后缀为 ...

  3. 关于使用CodeFirst,修改类或上下文时操作数据库报错解决方法

    在操作已经创建好的数据库时,若是添加新的实体类或者修改原有数据库上下文,会报如下错误: The model backing the 'StudentDbContext' context has cha ...

  4. 【转】Hudson插件Email-Ext邮件模板时间格式化的解决方法

    原文地址:http://www.cnblogs.com/haycco/archive/2012/03/20/3031397.html 最近因对Hudson版本进行了升级为2.2.0,所以各方面都在搞项 ...

  5. iOS的本地推送删除不了解决方法

    最近在研究苹果推送,当测试本地推送的时候,发现一个问题,就是一旦你添加了一个本地推动的通知,当你修改代码,删除应用,当你再次运行app,它还是会在横幅上面弹出推送,尼玛怎么搞都删除不了,近乎崩溃了,开 ...

  6. win10系统无法删除文件的解决方法

    方法/步骤 1:首先进入不能删除的文件所在的文件夹 2:右键单击此文件夹,选择授予访问权限 3:在授权界面选择删除权限 4:在删除权限中点击更改共享权限 5:我们选择administrator级别,点 ...

  7. XenCenter删除SR失败解决方法

    到CLI下 查SR的UUID xe sr-list SR的uuid=e0571e72-f6c5-1c9e-4ad8-9817b2331f47 FORGET SR xe sr-forget uuid=e ...

  8. python logging 日志轮转文件不删除问题的解决方法

    项目使用了 logging 的 TimedRotatingFileHandler : #!/user/bin/env python # -*- coding: utf-8 -*- import log ...

  9. 在 Visual Studio 中打开编辑 cshtml 文件时出现错误:未能完成该操作 无效指针 的解决方法

    第一步:关闭 Visual Studio: 第二步:删除 %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache 下的所有文件: ...

随机推荐

  1. mac随笔

    1.查看端口,lsof -i tcp:post lsof -i tcp:8086 2.kill进程 找到进程的PID,使用kill命令:kill PID(进程的PID,如2044),杀死对应的进程 k ...

  2. 《基于WEB的独立学院补考重修管理系统研究》论文笔记(二十)

    <基于WEB的独立学院补考重修管理系统研究>论文笔记(1) 一.基本信息 标题:基于WEB的独立学院补考重修管理系统研究 时间:2016 来源:南通大学杏林学院 关键词:WEB:补考重修管 ...

  3. 项目Alpha冲刺(团队)-第七天冲刺

    格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(团队) 团队名称:为了交项目干杯 作业目标:描述第七天冲刺的项目进展.问题困难.心得体会 队员姓名与学号 队员学号 ...

  4. Maven模块化搭建总结

    1.Maven插件在eclipse的安装 windows——>preferences——>Maven——>installations——>add——>installati ...

  5. centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

    客户端连接报错 这个问题是因为用户在数据库服务器中的mysql数据库中的user的表中没有权限. 解决步骤 1.连接服务器: mysql -u root -p 2.看当前所有数据库:show data ...

  6. LeetCode 1000. Minimum Cost to Merge Stones

    原题链接在这里:https://leetcode.com/problems/minimum-cost-to-merge-stones/ 题目: There are N piles of stones ...

  7. SpringBoot-设置定时任务

    @Scheduled为设置定时任务的注解. 参数常用的为两种: 第一种是fixedRate,表示以一种固定频率去执行,单位为毫秒:例如@Scheduled(fixedRate = 5000)  表示为 ...

  8. Xamarin.IOS/Mac开发中遇到的问题

    虚拟机中安装的mac系统无法识别iphone 今天在 Xamarin.iOS 应用的免费预配 时,进行到 5.插入要在其中部署应用的 iOS 设备. 在第8选择iphone设备时,发现iphone并没 ...

  9. packr 方便的潜入静态资源文件到golang 二进制文件中

    类似的工具以前有介绍过statik,今天使用的工具是packr 也是很方便的golang tools 安装 go get -u github.com/gobuffalo/packr/packr 或者我 ...

  10. redis 设置为只读模式

    数据库的只读模式,对于在系统出现重大故障,但是又不影响用户的查询操作还是很重要的 对于redis 设置只读模式需要分不同的场景 master-slave cluster single master-s ...