we want to save an Aspose.MailMessage in msg-format and stream the generated msg-file via our web application to the user. The user should edit the streamed message with his E-Mail-Application like Outlook.
Is this possible with Aspose?
All such attempts open an readonly message for the user.
MailMessage mailMsg = new MailMessage();
mailMsg.From = "email@example.com";
mailMsg.To = "firstname.lastname@example.org";
mailMsg.Subject = “Test Subject”;
mailMsg.Body = “Email Body”;
// create instance of type MapiMessage from MailMessage
MapiMessage mapiMsg = MapiMessage.FromMailMessage(mailMsg);
// set message flag to un-sent
// save it - Here you can save it to Memorystream in editable mode now.
MemoryStream ms = new MemoryStream();
Thank you for your help. Now it works fine.
I assume from this topic that the mail message should open with Outlook so that it could possible be edited before sending.
This is not happening for me. I am not prompted to open a file and it does not happen automatically. Is there something that I am still missing?
I am doing this in a vb.net web application.
Thanks in advance!
Please find code snip attached. It is basically the same code as above but converted to VB.
I trigger this from a button click.
Thank you for your reply.
The code you have supplied me does indeed work however not exactly in the way I would like it to work.
I do not have a need to save the msg file. The problem with the msg file is that the user has to go and retrieve it before sending.
I was hoping to be able to generate the file as a memory stream and then have the application open the file in Outlook automatically - working in a similar way to the way Aspose.Words does.
There is no need to store a copy of the email message on file - it can be regenerated by the application if needed.
I hope that this is clear.
- Create mail message
- Convert it to MapiMessage
- Save MapiMessage to a memory stream
- Set content type of the Response
- Send MapiMessage as stream of bytes to client browser
mailMessage.From = "anyone@myCompany.com"
mailMessage.TextBody = “any Body”
mailMessage.Subject = “any Subject”
Dim mailOutlookMapiMessage As MapiMessage = MapiMessage.FromMailMessage(mailMessage)
Dim mailStream As MemoryStream = New MemoryStream()
mailStream.Position = 0
Dim buffer() As Byte
Buffer = mailStream.ToArray() 'save in byte array
Response.Buffer = True
Response.ContentType = “application/vnd.ms-outlook”
Response.AddHeader(“content-disposition”, “attachment;filename=” + “Sample.msg”)
On execution of this code “Sample.msg” file will be downloaded to the client browser and user will have the option to open this file in MS Outlook in draft mode. After editing the mail, user will be allowed to Send the mail.
Yes, this is what I was looking for.
Thank you for your help.