Hi,
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.
Hi,
MailMessage mailMsg = new MailMessage();
mailMsg.From = "from@domain.com";
mailMsg.To = "to@domain.com";
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
mapiMsg.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
// save it - Here you can save it to Memorystream in editable mode now.
MemoryStream ms = new MemoryStream();
mapiMsg.Save(ms);
Hi,
Thank you for your help. Now it works fine.
Hi,
Hello,
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!
Hi Joe,
Hello,
Please find code snip attached. It is basically the same code as above but converted to VB.
I trigger this from a button click.
Joe
Hi Joe,
outlookMsg.Save(“Sample01.msg”)
outlookMsg.Save("Sample02.msg")
Hello Kashif,
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.
Joe
Hi Joe,
- 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)
mailOutlookMapiMessage.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT)
Dim mailStream As MemoryStream = New MemoryStream()
mailOutlookMapiMessage.Save(mailStream)
mailStream.Position = 0
Dim buffer() As Byte
Buffer = mailStream.ToArray() 'save in byte[] array
Response.Clear()
Response.Buffer = True
Response.ContentType = “application/vnd.ms-outlook”
Response.AddHeader(“content-disposition”, “attachment;filename=” + “Sample.msg”)
Response.BinaryWrite(Buffer)
Response.End()
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.
Hello Kashif,
Yes, this is what I was looking for.
Thank you for your help.
Joe
Hi Joe,