views:

313

answers:

3

I need to send a vcal file in email.I want to send file without creating it disk. I has file in string format.

A: 

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.

You can generate temporary filenames with functions like mktemp.

Ben Alpert
A: 

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.

sybreon
+1  A: 

Here's what I think you are looking for in 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'.

slolife