【发布时间】:2017-05-01 12:10:56
【问题描述】:
我正在尝试将我的收件箱电子邮件复制到文本文件,然后在此文本文件中搜索 word。如果这个词存在,我将使用这个词从 db 中查询 email-id 最后将这封邮件转发到这个 email-id。 我的问题是我无法将电子邮件复制到文本文件中。 msg 变量始终为空 这是我的代码:
using (Pop3Client client = new Pop3Client())
{
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("mymail@gmail.com", "pasword", AuthenticationMethod.UsernameAndPassword);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
for (int i = messageCount; i > 0; i--)
{
string msg = client.GetMessage(i).MessagePart.GetBodyAsText().ToString();
System.IO.File.WriteAllText(@"d:\\My File2.log", msg.ToString());
var body = System.IO.File.ReadLines(@"d:\\My File2.log");
if (body.Contains("cusotmer ID: X"))
{
getemailadress();
sendemail();
}
}
}
【问题讨论】:
-
您忘记提问了吗?
-
您的代码在什么方面不起作用?描述问题。
-
为什么要将消息正文写入文件,然后再次读取以搜索文本。只需从 msg 变量中读取它,然后将其保存为成功或失败。
-
@marwen1:您编辑了问题,但没有添加任何信息。请具体描述问题是什么。实际上是什么失败了?您是否遇到某种错误?意外的结果/行为?当您调试时,具体会发生什么以及您预期会发生什么?
-
@david :没有收到任何错误我的问题是文本文件总是空的。我的问题 hir :string msg = client.GetMessage(i).MessagePart.GetBodyAsText().ToString();
标签: c# asp.net .net asp.net-mvc-4