获取 MailMessage 附件的路径
我正在使用 MailMessage 队列,退出程序后我想保存队列的内容。
我创建了一个临时列表并将队列的内容传递给它。之后使用一个简单的 StreamWriter
写出每个信息。
我似乎唯一无法得到的是附件的路径。据我所知,我不能只是简单地保存邮件消息,所以我认为这也同样有效,但如果有更简单/不同的解决方案,那就太好了。
List<MailMessage> temp = queue.ToList<MailMessage>();
Stream stream = File.Open("Queue" +".osl", FileMode.Create);
StreamWriter s = new StreamWriter(stream);
foreach (MailMessage x in temp)
{
s.WriteLine(x.From.Address + x.To[0].Address + x.Body + x.Subject + x.Attachments[0].Name);
}
s.Close();
stream.Close();
I'm using a MailMessage Queue and upon exiting the program I want to save the content of the queue.
I created a temp list and pass the contents of the queue to that. After that use a simpleStreamWriter
to write each info out.
The only thing I can't seem to get is the path of the attachment. As far as I know I can't just simply save out the mailmessages so I thought this will work just as well, but if there is simpler/different solution that's great.
List<MailMessage> temp = queue.ToList<MailMessage>();
Stream stream = File.Open("Queue" +".osl", FileMode.Create);
StreamWriter s = new StreamWriter(stream);
foreach (MailMessage x in temp)
{
s.WriteLine(x.From.Address + x.To[0].Address + x.Body + x.Subject + x.Attachments[0].Name);
}
s.Close();
stream.Close();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个老问题,但这里没有答案,这确实有效:
在您的具体情况下,它会是:
希望它对某人有帮助!
I know it is an old question, but there is no answer here, and this really works:
In your specific case it would be:
Hope it helps somebody!
您还可以使用:
You can also use: