I would like to create a new outlook Message from an .eml template. I have chosen to do this by converting .eml to .msg first and then creating a new Outlook.MailItem with the following code
FileName = "test.eml"
Dim MsgTemplateName As String = Path.GetTempFileName
Dim MsgTemplate As MailMessage = MailMessage.Load(FileName)
MsgTemplate.Save(MsgTemplateName, MessageFormat.Msg)
Dim Item as Outlook.MailItem = _OutlookApp.CreateItemFromTemplate(MsgTemplateName)
Now after this I capture the send event and convert the MailItem back to .eml Format. I need to do this because I want to send the message via a different SMTP Server, not the one the Outlook Application is connected to:
Dim MsgTemplateName As String = Path.GetTempFileName
Item.SaveAs(MsgTemplateName, Outlook.OlSaveAsType.olMSG)
Dim Msg As MapiMessage = MapiMessage.FromFile(MsgTemplateName)
Dim MsgInterpretor As MailMessageInterpretor = MailMessageInterpretorFactory.Instance.GetIntepretor(Msg.MessageClass)
Dim Eml As MailMessage = MsgInterpretor.Interpret(Msg)Eml.Save(_TemplateFileName)
However, during this process the resulting .eml file seems to lose the MIME information of its inline images like so:
------=_NextPart_001_000C_01C22027.C6636010
Content-Type: text/html; charset=“iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<img src=3D"cid:test” height=3D"451" width=3D"600">------=NextPart_001_000C_01C22027.C6636010–
------=NextPart_000_000B_01C22027.C6636010
Content-Type: image/gif;
name="test.gif"
Content-Transfer-Encoding: base64
Content-ID: etc.
becomes:
Content-Type: application/octet-stream
Also, the subject =?iso-8859-1?Q?Fr=F6hliche_Weihnachten?= is replaced by:
Subject:
=?utf-32?Q?F=00=00=00r=00=00=00=F6=00=00=00h=00=00=00l=00=00=00i=00=00=00?=
=?utf-32?Q?c=00=00=00h=00=00=00e=00=00=00=00=00=00W=00=00=00e=00=00=00i?=
=?utf-32?Q?=00=00=00h=00=00=00n=00=00=00a=00=00=00c=00=00=00h=00=00=00t?=
=?utf-32?Q?=00=00=00e=00=00=00n=00=00=00?=Subject:
=?utf-32?Q?F=00=00=00r=00=00=00=F6=00=00=00h=00=00=00l=00=00=00i=00=00=00?=
=?utf-32?Q?c=00=00=00h=00=00=00e=00=00=00=00=00=00W=00=00=00e=00=00=00i?=
=?utf-32?Q?=00=00=00h=00=00=00n=00=00=00a=00=00=00c=00=00=00h=00=00=00t?=
=?utf-32?Q?=00=00=00e=00=00=00n=00=00=00?=
Is this because I am doing the conversion in the wrong way? Or does it have to do with Outlook and can’t be worked around? I’d be most thankful for any help, thanks in advance!
With regards,
Guido