Hi,
I need your help with Aspose.Email.dll.
In my scenario I receive messages directly from Exchange Agent (they are EML messages with root part of "application/ms-tnef" content-type). I need to examine the insides of message, make some changes to embedded message (to simplify the topic let’s think that I need to replace all PNG images from all embedded messages with one passed as a parameter) and send it back to Exchange in the same format – EML message with “winmail.data” of "application/ms-tnef" content-type.
Winmail.dat contains all information about main message. The key point here is that all embedded messages are also in TNEF format.
I attached simple message from Exchange: “ExchangeMessage.eml”. Test project is also attached.
Test01
First I tried to read main message with MailMessage class (see Test01 in project). In this case embedded message is automatically converted from TNEF format to .MSG format. You can easily save it to disk (“01_embedded_message.msg”) and open by Outlook. So I read this embedded message; replaced PNGs and saved back to MSG format. Then I changed content stream of embedded message in main message and tried to save main message.
But in this case message is saved without “winmail.dat” – message became “multipart/mixed” – TNEF is not retained (see "01_ ExchangeMessage_SAVE.msg"). Embedded message is saved as MSG attachment.
Then I tried to use other Save-method of MailMessage with FileCompatibilityMode (set to PreserveTnefAttachments). In this case TNEF is preserved, but contains original embedded message, because signature image in embedded message is old.
Test02
Then I tried to use MapiMessage (please see Test02 in project). I got InvalidOperationException with message “This is not a structured storage file.”.
So I manually removed all headers – left only “bare” winmail.dat (“ExchangeMessageOnlyWinmail.dat.eml” file in the project) and tried LoadFromTnef method. Message is successfully read. But I cannot save it back to TNEF – SaveAsTnef method throws ArgumentNullException exception “Value cannot be null. Parameter name: data”.
Test03
I also found that MapiMessage.FromProperties method works incorrectly. It shows that embedded message does not have attachments.
But if you save embedded message of main message and use MapiMessage.FromFile – it shows attachments.
<span style=“font-size:11.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:“Times New Roman”;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>So can you please help me find out a way to change
embedded messages and save main message back to the original format?
Thank you,
Alex Shloma
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>RU</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>