如何在不将文件保存到磁盘的情

时间:2022-11-14 07:37:31

I need to send a vcal file via email. I want to send the file without creating it on disk. I have the file in string format.

我需要通过电子邮件发送vcal文件。我想发送文件而不在磁盘上创建它。我有字符串格式的文件。

3 个解决方案

#1


1  

Here's what I think you are looking for in C#

这是我认为你在C#中寻找的东西

 System.IO.StringReader stream = new System.IO.StringReader("xyz");
 Attachment attach = new Attachment(stream);
 MailMessage msg = new MailMessage();
 msg.Attachments.Add(attach);
 SmtpClient client = new SmtpClient();
 client.Send(msg);

"xyz" should be replaced with the string of the attachment. The code above will allow you to add an attachment to a MailMessage object without ever having to retrieve that object's data from disk, which is what I think you meant instead of 'memory'.

应将“xyz”替换为附件的字符串。上面的代码将允许您向MailMessage对象添加附件,而无需从磁盘检索该对象的数据,这就是我认为您的意思而不是“内存”。

#2


0  

Probably the best you can do (if you're using a graphical email program) is just save the .vcal file to a temporary directory, then pass that path to the mail program.

您可以做的最好的事情(如果您使用的是图形电子邮件程序)只是将.vcal文件保存到临时目录,然后将该路径传递给邮件程序。

You can generate temporary filenames with functions like mktemp.

您可以使用mktemp等函数生成临时文件名。

#3


0  

I'm not sure what you mean by not 'creating it memory'. Operating systems work by reading any file from disk into in-memory buffers. So, chances are that the file will still reside in memory at some point. Furthermore, when you pass the file over to the programme or tool that will dispatch it, it will also pass through some memory buffer.

我不确定你的意思是不是“创造记忆”。操作系统通过将任何文件从磁盘读入内存缓冲区来工作。因此,很可能文件在某些​​时候仍会驻留在内存中。此外,当您将文件传递给将调度它的程序或工具时,它也将通过一些内存缓冲区。

#1


1  

Here's what I think you are looking for in C#

这是我认为你在C#中寻找的东西

 System.IO.StringReader stream = new System.IO.StringReader("xyz");
 Attachment attach = new Attachment(stream);
 MailMessage msg = new MailMessage();
 msg.Attachments.Add(attach);
 SmtpClient client = new SmtpClient();
 client.Send(msg);

"xyz" should be replaced with the string of the attachment. The code above will allow you to add an attachment to a MailMessage object without ever having to retrieve that object's data from disk, which is what I think you meant instead of 'memory'.

应将“xyz”替换为附件的字符串。上面的代码将允许您向MailMessage对象添加附件,而无需从磁盘检索该对象的数据,这就是我认为您的意思而不是“内存”。

#2


0  

Probably the best you can do (if you're using a graphical email program) is just save the .vcal file to a temporary directory, then pass that path to the mail program.

您可以做的最好的事情(如果您使用的是图形电子邮件程序)只是将.vcal文件保存到临时目录,然后将该路径传递给邮件程序。

You can generate temporary filenames with functions like mktemp.

您可以使用mktemp等函数生成临时文件名。

#3


0  

I'm not sure what you mean by not 'creating it memory'. Operating systems work by reading any file from disk into in-memory buffers. So, chances are that the file will still reside in memory at some point. Furthermore, when you pass the file over to the programme or tool that will dispatch it, it will also pass through some memory buffer.

我不确定你的意思是不是“创造记忆”。操作系统通过将任何文件从磁盘读入内存缓冲区来工作。因此,很可能文件在某些​​时候仍会驻留在内存中。此外,当您将文件传递给将调度它的程序或工具时,它也将通过一些内存缓冲区。