Need help understanding why this Applescript works with Outlook 2011 for Mac but not Outlook 2016 or 2019 for Mac

FreeVet99 1 Reputation point
2020-09-02T14:00:12.38+00:00

Test 1 using Outlook 2016 or 2019
What we are doing is creating a test message and saving as eml file. When this file is opened and then replied to using the script the original sent date in the header that now shows in message body gets changed to the current date/time. This only happens in Outlook 2016 and 2019. Outlook 2011 keeps the original date and time.
Test 1 using Outlook 2016 or 2019

  1. Create a simple email in Outlook with subject as test, body as test, and to address to yourself.
  2. Send the message, if used yourself the message should come into your inbox as a new message.
  3. Open the message and take note of the sent date/time.
  4. Export the new email to the /Users/Shared folder. Should be called test.eml
  5. Wait for some time to go by like 5 minutes. If you open the eml file in Outlook you will see the date and time from when sent from earlier time.
  6. Open Script Editor
  7. Copy and paste the following script into the editor:

set theFile to (POSIX file "/Users/Shared/test.eml")
open for access theFile
set fileContents to (read theFile)
close access theFile

tell application "/Applications/Microsoft Outlook.app"
set SelectedMessages to current messages
repeat with theMsg in SelectedMessages
set msgID to id of theMsg
set theAccount to account of the message id msgID
set theSender to sender of the message id msgID
set theDt to time received of the message id msgID
set theMsg to make new incoming message at (deleted items of theAccount) with properties {sender:theSender, source:fileContents, account:theAccount}
set replyWindow to reply to theMsg
permanently delete theMsg
exit repeat
end repeat
end tell

  1. Now when you compile and run the Applescript it will open the eml file and create a new reply message in window but the date in the header of the original message is changed to the current date and time. This date should remain as the original sent date. What changes can I make to this script to make it work properly?

Test 2 using Outlook 2011

  1. Create a simple email in Outlook with subject as test, body as test, and to address to yourself.
  2. Send the message, if used yourself the message should come into your inbox as a new message.
  3. Open the message and take note of the sent date/time.
  4. Export the new email to the /Users/Shared folder. Should be called test.eml
  5. Wait for some time to go by like 5 minutes. If you open the eml file in Outlook you will see the date and time from when sent from earlier time.
  6. Open Script Editor
  7. Copy and paste the following script into the editor:

set theFile to (POSIX file "/Users/Shared/test.eml")
open for access theFile
set fileContents to (read theFile)
close access theFile
tell application "/Applications/Microsoft Office 2011/Microsoft Outlook.app"
set SelectedMessages to current messages
repeat with theMsg in SelectedMessages
set msgID to id of theMsg
set theAccount to account of the message id msgID
set theSender to sender of the message id msgID
set theDt to time received of the message id msgID
set theMsg to make new incoming message at (deleted items of theAccount) with properties {sender:theSender, source:fileContents, account:theAccount}
set replyWindow to reply to theMsg
permanently delete theMsg
exit repeat
end repeat
end tell

  1. Now when you compile and run the Applescript it will open the eml file and create a new reply message in window but the date in the header of the original message is as expected with the older date and time shown.

I would like to keep the Applescript code above as similar as possible, however if there is a better way of doing this then maybe time to change as needed. The difference in behavior was changed in 2016. Is there any minor changes I can make to my current Applescript code to keep the original date and time? Can someone explain to me why this behavior changed? Thanks in advance to anyone who can help with this.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
38,694 questions
{count} votes

2 answers

Sort by: Most helpful
  1. FreeVet99 1 Reputation point
    2020-09-03T00:53:54.117+00:00

    While this is Applescript question, it is specific to the Applescript Library Microsoft built into Outlook for Mac. Microsoft built this library for those who would like to automate, access capabilities, etc of their products on a Mac computer. So I do believe this post to be in the correct location. Hopefully someone from Microsoft in the right team will answer this question if no one else knows the answer. I will give this post some time here but if no answer soon I will post to one of the Apple communities like you said @John Korchok . I did have a ticket originally with Apple development and they referred me to Microsoft being it was Microsoft's library and because Microsoft should be able to better answer why the behavior changed from Outlook 2011 to 2016.

    Fingers crossed and hopeful. But if I do get answer eventually from some other source I will come back here and update with my findings.

    0 comments No comments

  2. Jade Liang-MSFT 9,976 Reputation points Microsoft Employee
    2020-09-03T07:21:35.34+00:00

    Hi @FreeVet99 ,
    Thanks for visiting our forum.

    As JohnKorchok mentioned, here we mainly focus on general issues about Outlook desktop client and we may know little about AppleScript development. Usually, for different versions of Outlook we may need different script configurations in some fields, which means the codes might need to be modified. I really want to help you and indeed did some search about it. However I have not found useful information. In order to better solve your issue, it is suggested to post a new thread in the more dedicated forum for Outlook for Developers , where there are many experts in development and also many threads related to AppleScript to reference:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thanks for your understanding and hope your question will be resolved soon.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.