I am writing a function in Java to forward Outlook emails. When using ews-java-api 2.0, I found that the time zone of the original email’s sent time attached to the forwarded email is UTC, not the UTC+8 time zone where I am located. Is there any way to solve this? Thank you!
This my pom.xml:
<dependency>
<groupId>com.microsoft.ews-java-api</groupId>
<artifactId>ews-java-api</artifactId>
<version>2.0</version>
</dependency>
This my code:
EmailMessage message = EmailMessage.bind(exchangeService, new ItemId(this.messageId));
ResponseMessage responseMessage = null;
responseMessage = message.createForward();
MessageBody messageBody = new MessageBody();
messageBody.setBodyType(BodyType.HTML);
messageBody.setText(html);
responseMessage.setSubject(this.subject);
responseMessage.setBodyPrefix(messageBody);
setResponseMessageRecipients(responseMessage);
responseMessage.sendAndSaveCopy();
I tried setting the time zone to UTC+8 before initializing ExchangeService and changed my computer’s time zone to UTC, but the sent time of the original email did not change.
TimeZone tz = TimeZone.getTimeZone("GMT+8");
TimeZone.setDefault(tz);
user10651075 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.