开发者

How should one attach an XDocument to a MailMessage in C#?

开发者 https://www.devze.com 2023-01-27 04:55 出处:网络
I have a C# form whose input I am aiming to turn into an xml document to attach to an email sent to myself. So far I\'ve got an XDocument which I believe is complete, and I have also figured out how t

I have a C# form whose input I am aiming to turn into an xml document to attach to an email sent to myself. So far I've got an XDocument which I believe is complete, and I have also figured out how to attach a .txt to the MailMessage with:

MailMessage.Attachments.Add(new Attachment("[...]\test.txt"));

My understanding is that I could use

XDocument.Save("[...]\formData.xml");

to save the file and then

MailMessage.Attachments.Add(new Attachment("[...]\formData.xml"));

to load and att开发者_如何学Cach it, but this seems wasteful.

Does anyone have a better way of going about this? I figure there must be a way to attach the XDocument without having to go to the file system like that...


Check out the Attachment class; you can add attachments by numerous other methods than just from a file, such as from a stream or string content:

http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号