获取 MailMessage 附件的路径

发布于 2024-11-18 04:28:05 字数 552 浏览 2 评论 0原文

我正在使用 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 simple
StreamWriter 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明月夜 2024-11-25 04:28:05

我知道这是一个老问题,但这里没有答案,这确实有效:

(attachmentObject.ContentStream as System.IO.FileStream).Name

在您的具体情况下,它会是:

s.WriteLine(x.From.Address + x.To[0].Address + x.Body + x.Subject + (x.Attachments[0].ContentStream as System.IO.FileStream).Name);

希望它对某人有帮助!

I know it is an old question, but there is no answer here, and this really works:

(attachmentObject.ContentStream as System.IO.FileStream).Name

In your specific case it would be:

s.WriteLine(x.From.Address + x.To[0].Address + x.Body + x.Subject + (x.Attachments[0].ContentStream as System.IO.FileStream).Name);

Hope it helps somebody!

得不到的就毁灭 2024-11-25 04:28:05

您还可以使用:

Path.GetFullPath(x.Attachments[0].Name);

You can also use:

Path.GetFullPath(x.Attachments[0].Name);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文