Email sent time showed by receiver's time zone

One email is sent out to Japan.
However the sent time is showed by Japan local time in the PDF file.
When I debug the email date, it is the Pacific Time.
Please let me know.

Thanks,
Chang Shin

It is the sent time: <!–[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>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<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]–><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:
<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”>
Wednesday, October 30, 2013 5:59 PM


in the PDF and mhtml file:
<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:31 Oct 2013
00:58:57 +0000



Thanks,
Chang Shin

<!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–>

Hi Chang,


Thanks for writing to us.

Aspose.Email provides liberty to display dates in selected time zones to the mhtml file and hence in PDF file which uses this mhtml. Following is a sample code that demonstrates the configuration of time zone in the output mhtml file using MailMessage.TimeZoneOffset.

string dir = @"";
MailMessage mail = MailMessage.Load(dir + “Sample.msg”);
mail.Save(dir + “Sample.mhtml”, MessageFormat.Mht,MailMessageSaveOptions.WriteHeaderToMht);

mail.TimeZoneOffset = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
// The dates will be rendered by local system time zone.
mail.Save(dir + “Local System Time Zone Sample.mhtml”, MessageFormat.Mht, MailMessageSaveOptions.WriteHeaderToMht);

// Set custom time zone offset for message date (0900).Japan UTC time
mail.TimeZoneOffset = new TimeSpan(9, 0, 0);
// Dates will be rendered by custom time zone.
mail.Save(dir + “Japan Time Zone Sample.mhtml”, MessageFormat.Mht, MailMessageSaveOptions.WriteHeaderToMht);


// Set custom time zone offset for message date say (-0800).
mail.TimeZoneOffset = new TimeSpan(-8, 0, 0);//just a random choice for time zone
// Dates will be rendered by custom time zone.
mail.Save(dir + “Sample with -08 UTC Time Zone.mhtml”, MessageFormat.Mht, MailMessageSaveOptions.WriteHeaderToMht);


// We can also change the kind of mail date as follows
if (mail.Date.Kind == DateTimeKind.Local)
{
mail.Date = mail.Date.ToUniversalTime();
}

Please feel free to write us back if you have any other query in this regard.

I am using java.
There is no codes like that.
Can you give the java codes?
We use local pacific time zone.

Thanks,
Chang Shin

We do not create an email file.
we just read an email file and convert to PDF file.
When you give me the java code, please use the full package name.
If your library use the same as others, I don’t know which the right is.

Thanks,
Chang Shin


When I debug the message date, the date is “message.getDate()=2013-10-30 17:58:57”.
however the pdf file and mhtml are not same,
<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:31 Oct 2013
00:58:57 +0000


Even if I use this command, the date is not effected:
TimeZone tz = TimeZone.getTimeZone(“America/Los_Angeles”);
///tz.getOffset(Calendar.ZONE_OFFSET);
message.setTimeZoneOffset(tz.getOffset(Calendar.ZONE_OFFSET) ) ;
<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”>

Hi Chang,

We are sorry for the confusion where we provided you the .NET code instead of Java. You can use the setTimeZoneOffset method to set the timezone of the message as per your convenience. Please have a look at the following code sample that loads and saves the message with Japanese time offset. At present the seTimeZoneOffset accepts a numeric value in seconds to set the offset of the message. Please let us know if you have any other query/inquiry in this regard.

Sample Code:

com.aspose.email.License lic = new com.aspose.email.License();
lic.setLicense(fiStream2);

MailMessage msg = MailMessage.load("11059SV23000BB9.msg");
msg.setTimeZoneOffset(9 * 60 * 60 * 1000);
msg.save("output.mhtml", MailMessageSaveType.getMHtmlFormat());

No, It does not work.
I don’t need to create anemail file.
I just read an email file and convert to PDF file.

Thanks,
Chang Shin

Hi Chang,


I am afraid to inform that I could not understand the requirement of not creating the email file. In the above mentioned example, mail is not created but read from the disc.

For further clarification a complete project is attached here which reads an email file, changes its timezone to Japan (+9) by setting the number of milliseconds in MailMessage.setTimeZoneOffset() function. This modified email is then converted to mhtml and PDF having the updated timezone. Could you please give it a try and let us know your feedback? If it does not fulfill your requirement, please provide more detail along with the sample data (if any).

Your understanding and patience is highly appreciated in this regard.

P.S.I used Eclipse IDE along with Aspose.Email for Java 3.5.0 and Aspose.Words for Java 13.9.0.

We want the same date as email data in the PDf file. not japan time zone date.
It is the email date to be sent out to japan.
the date is “message.getDate()=2013-10-30 17:58:57”.
however the pdf file and mhtml are converted to Japan time zone.

<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:31 Oct 2013
00:58:57 +0000 in the PDF file.

It is not correct.
We want the same email date time in the PDF file.

Now It woks. but some time is one hour different by daylight saving time.
How can I fix the one hour different?
Also how can I change “Sent” date format?

Thanks,
Chang Shin


I found the timezone set:
but I don’t know how to set the date format.
The default format is Day, Month year hh:mm:ss
4 Nov 2013 17:33:58 -0800

We need US format: Month name, day year hh:mm:ss
November 4 2013 17:33:58

We never used the timezone offset.
I don’t know why the Sent date and format is changed from last week.

Thanks,
ChangShin

Hi Chang,

This is the default date format that is written to the output MHTML file. If you want to set the date format as per your requirements, the MhtMessageFormatter class could have been used here as shown in the following sample code. However, I have observed that MhtMessageFormatter does not take into account the TimeZone Offset. I’m further investigating this issue and will share my findings here with you shortly.

Sample Code:

MailMessage eml = MailMessage.load(fileName);
eml.setTimeZoneOffset(9 * 60 * 60 * 1000);

MhtMessageFormatter f = new MhtMessageFormatter();
f.setDateTimeFormat("MMM d yyyy HH:mm:ss");
f.format(eml);

eml.save(fileName + ".mhtml", MailMessageSaveType.getMHtmlFormat(), MailMessageSaveOptions.None);

Now It works.
when and how come the default format is changed?
Anyhow quick and good responding and solution.

Thanks,
Chang Shin

It is what I got the timezoen offset:
TimeZone timezone = TimeZone.getTimeZone(“America/Los_Angeles”);
double offset = timezone.getOffset(Calendar.ZONE_OFFSET);

Calendar c = Calendar.getInstance(timezone); // omit timezone for default tz
c.setTime(message.getDate()); // your date; omit this line for current date
int dateOffsetInt= c.get(Calendar.DST_OFFSET);
int offSetint = Double.valueOf(offset).intValue()+dateOffsetInt;
offset = Double.parseDouble(offSetint + “”);
log.info(“Offset value:” + Double.valueOf(offset).intValue());
message.setTimeZoneOffset(offset);
MhtMessageFormatter mhtlFormat = new MhtMessageFormatter();
mhtlFormat.setDateTimeFormat(“EEEE, MMMM d, yyyy hh:mm:ss a”);
mhtlFormat.format(message);
message.save(baseFolder + htmlFileName, MailMessageSaveType.getMHtmlFormat(), MailMessageSaveOptions.None);

One more question.

how come the From has double quote like this?:
From: “Chang Shin” chang@email.com
Only name without double quote was converted until last week.
Can we change the from , To, and CC format too?

Thanks,
Chang Shin

Hi Chang,


I have tried your code with my sample files and found that the TimezoneOffset setting is not effective after MhtMessageFormatter is used. It seems that the header information displayed by MhtMessageFormatter is not taking TimezoneOffset into account.

I have logged this issue in our issue tracking system as ID:NETWRKJAVA-33324. Development team will look into it and once we have any information regarding the resolution of this issue, we’ll update you here via this thread.

If you have any other query/inquiry regarding Aspose.Email, please feel free to post to us. We’ll try to assist you further as soon as possible.


So are the double quote and extra email address for From, To, and CC from this issue?
We never used the timezone offset, how come we have the timezone problem from last week?
I have to report this issue to my manager.

Thanks,
Chang Shin

Hi Chang,


I have tried to re-produce the issue using current release Aspose.Email for Java 3.5.0 and previous release Aspose.Email for Java 3.4.0 but could not observe the difference of double quote in the From field. Could you please provide us the sample code along with the sample EML to re-produce the issue here.

Regarding formatting the To, From and CC, please give a try to the following code which changes these headers.

static void TestHeadersFormatting()
{
String fileName = “Sample”;
String strEMLFile = fileName + “.eml”;
String strMHTFile = fileName + “.mhtml”;
String strPdfFile = fileName + “.pdf”;
MailMessage msg = MailMessage.load(strEMLFile);
MhtMessageFormatter mailFormatter = new MhtMessageFormatter();
mailFormatter.setFromFormat("<span class=“headerLineTitle”>New From:<span class=“headerLineText”> {0}
");
mailFormatter.setDateTimeFormat(“dd.MM.yyyy HH:mm”);
mailFormatter.setSentFormat("<span class=“headerLineTitle”>New Sent:<span class=“headerLineText”> {0}
");
mailFormatter.setToFormat("<span class=“headerLineTitle”>New To:<span class=“headerLineText”> {0}
");
mailFormatter.setSubjectFormat("<span class=“headerLineTitle”>New Subject:<span class=“headerLineText”> {0}
");
mailFormatter.setBccFormat("<span class=“headerLineTitle”>New Bcc:<span class=“headerLineText”> {0}
");
mailFormatter.setCcFormat("<span class=“headerLineTitle”>New Cc:<span class=“headerLineText”> {0}
");
mailFormatter.setAttachmentFormat("<span class=“headerLineTitle”>New Attachment:<span class=“headerLineText”> {0}
");
mailFormatter.format(msg);
msg.save(“Sample.mhtml”, MailMessageSaveType.getMHtmlFormat(),MailMessageSaveOptions.None);
}

P.S. It is highly recommended to start new thread for any new issue.

The email sample and the pdf file are attached.
the email is just from your response email.

Thanks,
Chang Shin

Your sample code does not work.
still has the double quote and extra email address.

Thanks,
Chang Shin