C# 使用.net中的Pop3.dll从邮箱下载电子邮件附件
我正在使用VS2010使用c#开发winform应用程序 对于从邮箱加载电子邮件附件,我使用了pop3.dll 当我在直接连接到internet的计算机上使用我的代码下载附件时,但当我在ISA server 2004用作防火墙的域中使用它时,我的代码只显示邮箱中有多少邮件,然后等待 请任何人告诉我为什么以及我应该做什么来解决这个问题 这是密码C# 使用.net中的Pop3.dll从邮箱下载电子邮件附件,c#,.net,winforms,pop3,email-attachments,C#,.net,Winforms,Pop3,Email Attachments,我正在使用VS2010使用c#开发winform应用程序 对于从邮箱加载电子邮件附件,我使用了pop3.dll 当我在直接连接到internet的计算机上使用我的代码下载附件时,但当我在ISA server 2004用作防火墙的域中使用它时,我的代码只显示邮箱中有多少邮件,然后等待 请任何人告诉我为什么以及我应该做什么来解决这个问题 这是密码 public bool DownloadEmailWithAttachment(string Type) { try
public bool DownloadEmailWithAttachment(string Type)
{
try
{
EventLog.WriteEntry("Service", "Attachment Path :> " + AttachmentDir);
long count = 0;
Pop3Client email = new Pop3Client(UserName, Password, IncomingPopAddress);
email.OpenInbox();
//LogEntry();
EventLog.WriteEntry("Service", "Counter :> " + email.MessageCount);
while (email.NextEmail())
{
count = email.MessageCount;
if (email.IsMultipart)
{
IEnumerator enumerator = email.MultipartEnumerator;
while (enumerator.MoveNext())
{
Pop3Component multipart = (Pop3Component)enumerator.Current;
string checkIfFile = multipart.Filename;
if (checkIfFile != null)
{
//Console.WriteLine("checkIfFile.Contains('Leave') =" + checkIfFile.ToString());
EventLog.WriteEntry("Service", "checkIfFile.Contains('"+Type+"') =" + checkIfFile.ToString());
if (checkIfFile.Contains(""+Type))
{
EventLog.WriteEntry("Service", "Attachment name=" + multipart.Name); // ... etc
byte[] filebytes = Encoding.ASCII.GetBytes(multipart.Data);
//Search FileName
int fileLength = checkIfFile.Length;
EventLog.WriteEntry("Service", "fileLength=" + fileLength);
//int Begin = multipart.ContentType.IndexOf("name="+checkIfFile.ToString());
string leFileNale = checkIfFile.ToString();
EventLog.WriteEntry("Service", leFileNale);
FileStream LeFS = new FileStream(AttachmentDir + "\\" + leFileNale, FileMode.Create, FileAccess.Write, FileShare.None);
LeFS.Write(filebytes, 0, filebytes.Length);
LeFS.Close();
string DeleteMailContainingSubject = email.Subject.ToString();
if (email.Subject.Contains(DeleteMailContainingSubject))
{
email.DeleteEmail();
EventLog.WriteEntry("Service", "Email with Subject " + DeleteMailContainingSubject);
}
}
}
}
}
}
email.CloseConnection();
}
catch (Pop3LoginException ex)
{
EventLog.WriteEntry("Service","Exception :" + ex.ToString());
}
return true;
}
这是我下载电子邮件附件的代码。这是用于下载电子邮件的dll,我使用过类似openpop3、mail.dll等替代方案,但同样的问题也出现了。有几个可能的问题:首先,防火墙可能会阻止附件通过。如果是这样的话。。你需要找出原因。另一件事可能是它需要身份验证,以便对用户强制执行规则。由于您没有进行身份验证,这可能会强制执行非常严格的规则。您指的是哪种身份验证?在哪种文件上,我们可以从exchange server下载电子邮件附件。使用代码时,我们无法下载附件