I use the following code to convert the msg file to Tiff image<span style=“font-size:10.0pt;
font-family:“Tahoma”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”> and I want to change the format of the Sent date time from <span style=“font-size:10.0pt;
font-family:“Tahoma”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>Sent: Fri, 29 Apr 2016 08:34:14 -0500 to Sent: Fri 29-Apr-2016
8:34 AM
VB Code:
Dim _msg As MailMessage = MailMessage.Load(FilNam_In, New MsgLoadOptions())
Dim msgStream As MemoryStream = Nothing
Try
msgStream = New MemoryStream()
_msg.Save(msgStream, Aspose.Email.Mail.SaveOptions.DefaultMhtml)
'msgStream.Position = 0
Dim msgDocument As Aspose.Words.Document = New Aspose.Words.Document(msgStream)
For Each section As Aspose.Words.Section In msgDocument
section.PageSetup.PaperSize = Aspose.Words.PaperSize.Letter
section.PageSetup.BottomMargin = 20
section.PageSetup.TopMargin = 20
section.PageSetup.LeftMargin = 20
section.PageSetup.RightMargin = 20
Next section
For Each table As Aspose.Words.Tables.Table In msgDocument.GetChildNodes(Aspose.Words.NodeType.Table, True)
table.AllowAutoFit = True
table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.Auto
Next table
Dim _saveoptions As Aspose.Words.Saving.ImageSaveOptions = New Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Tiff)
_saveoptions.ImageColorMode = Aspose.Words.Saving.ImageColorMode.None
_saveoptions.PixelFormat = Aspose.Words.Saving.ImagePixelFormat.Format16BppRgb555
_saveoptions.SaveFormat = Aspose.Words.SaveFormat.Tiff
_saveoptions.TempFolder = Path.GetTempPath
_saveoptions.TiffCompression = Aspose.Words.Saving.TiffCompression.Lzw
_saveoptions.Resolution = 300.0
_saveoptions.UseHighQualityRendering = True
_saveoptions.ColorMode = Aspose.Words.Saving.ColorMode.Normal
_saveoptions.DmlRenderingMode = Aspose.Words.Saving.DmlRenderingMode.DrawingML 'Aspose.Words.Saving.DmlRenderingMode.Fallback
_saveoptions.DmlEffectsRenderingMode = Aspose.Words.Saving.DmlEffectsRenderingMode.Fine
_saveoptions.PrettyFormat = False
msgDocument.Save(FilNam_Out, _saveoptions) 'Aspose.Words.SaveFormat.Tiff)
Hi Lisa,
I tested the code above and it nearly works.
The code produced double headers, but I found the code to hide extra print header.
But, the tiff image has the sent line with the following date. “2/12/2015 10:36” and does not have AM/PM.
My new code:
Dim _msg As MailMessage = MailMessage.Load(FilNam_In, New MsgLoadOptions())
Dim mhtlFormat As New MhtMessageFormatter()
mhtlFormat.DateTimeFormat = “mm/dd/yyyy H:mm tt”
mhtlFormat.Format(_msg)
Dim msgStream As MemoryStream = Nothing
Try
msgStream = New MemoryStream()
Dim options As New MhtSaveOptions()
options.MhtFormatOptions = MhtFormatOptions.HideExtraPrintHeader
options.MailMessageSaveType = MailMessageSaveType.MHtmlFormat
_msg.Save(msgStream, options)
Dim msgDocument As Aspose.Words.Document = New Aspose.Words.Document(msgStream)
options = Nothing : msgStream.Dispose() : mhtlFormat = Nothing
Whats wrong?
Hi Liza,
MailMessage msg = MailMessage.Load(“snapshot.msg”, new MsgLoadOptions());
var mhtlFormat = new MhtMessageFormatter();
mhtlFormat.DateTimeFormat = “mm/dd/yyyy H:mm tt”;
mhtlFormat.Format(msg);
var msgStream = new MemoryStream();
var options = new MhtSaveOptions();
options.MhtFormatOptions = MhtFormatOptions.HideExtraPrintHeader;
options.MailMessageSaveType = MailMessageSaveType.MHtmlFormat;
msg.Save(“output.mht”, options);
msg.Save(msgStream, options);
var msgDocument = new Aspose.Words.Document(msgStream);
msgDocument.Save(“output.tiff”,SaveFormat.Tiff);
With the new code added, it is still not working.
By the way, the code given in the previous reply “<span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>mhtlFormat.DateTimeFormat
= “mm/dd/yyyy H:mm tt”;”<!–[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>EN-US</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]–>
at least for vb.net the line should have been
<span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>mhtlFormat.DateTimeFormat
= “MM/dd/yyyy H:mm tt”;
<!–[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>EN-US</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]–>
I have included a zip file that contains a text file with my complete procedure, and 2 screen captures. 1 of the mht file and 1 of the tiff image.
I am using the latest aspose dlls as of Feb 13 2017
Help
Hi,
Applied the change. Still not correct. see attached jpg
I tracked down the problem. For future reference, this is NOT your problem.
It was a problem on my development machine. In the control panel->Region and Language, my AM and PM was clear.
See attached.
Thanks for your help and patience
Hi,
Hi
I am using Aspose Email .Net 19.4.0.0
I do not see the MhtMessageFormatter. I am in need of changing the format of my email Sent date. Has this been replaced or am I missing something?
Thanks,
Charles
Can you please provide the sample code where you are trying to apply formatting so that we may investigate that further on our end.
public static class Aspose.Email.Mail.MthTemplateName - Defines well known names of headers for Mhtml formatting.
string file = Path.Combine(TestUtil.GetTestPath(), "Test email.msg");
MailMessage eml = MailMessage.Load(file, new MsgLoadOptions());
MhtSaveOptions mhtSaveOptions= new MhtSaveOptions();
mhtSaveOptions.FormatTemplates[MthTemplateName.DateTime] = "HH:mm:ss";
mhtSaveOptions.FormatTemplates[MthTemplateName.From] = @"<span class='headerLineTitle'>From:</span><span class='headerLineText'>{0}/span><br/>";
mhtSaveOptions.FormatTemplates[MthTemplateName.Sent] = @"<span class='headerLineTitle'>Sent:</span><span class='headerLineText'>{0}</span><br/>";
mhtSaveOptions.FormatTemplates[MthTemplateName.To] = @"<span class='headerLineTitle'>To:</span><span class='headerLineText'>{0}</span><br/>";
mhtSaveOptions.FormatTemplates[MthTemplateName.Cc] = @"<span class='headerLineTitle'>Cc:</span><span class='headerLineText'>{0}</span><br/>";
eml.Save(ms, saveOptions);
@ccuster68m,
I am pleased to hear that shared information served your purpose.