AppleScript Seach Mail in Outlook with Exchange/Internet ID - outlook

I am handling Outlook emails using the MS Graph API and with the API, it provides the 'Email ID' and 'Internet Message ID' for each email. I want to be able then display a specific email in the Outlook App using the ID's I received from the API. This is for MacOS so I thought it may be possible with AppleScript.
Is it possible to search an outlook mail using the 'Email ID' or 'Internet Message ID'. It seems like the 'Email ID' value from the API and the 'exchange ID' in appleScript are similar, but different.
Exchange Id used in AppleScript vs Email Id from API. Different but very similar:
Exchange ID from AppleScript:
AAMkADc2YjQwNTdhLTJhYzItNDA0Ni04MmNhLTRlM2Q5MDMxMGI1NwBGAAAAAAD/aipfqmVySpN0sC+1eNHeBwANqnfaKK5URZoJzj79Kz7GAAAAAAEMAAANqnfaKK5URZoJzj79Kz7GAAAXVu7QAAA=
Email Id from MS API:
AAMkADc2YjQwNTdhLTJhYzItNDA0Ni04MmNhLTRlM2Q5MDMxMGI1NwBGAAAAAAD-aipfqmVySpN0sC_1eNHeBwANqnfaKK5URZoJzj79Kz7GAAAAAAEMAAANqnfaKK5URZoJzj79Kz7GAAATOkOyAAA=
This is what I have so far:
tell application "Microsoft Outlook"
set theFolder to mail folder "Inbox" of exchange account "<Account_Name>"
set theMsg to first message of theFolder whose exchange id is "<ID>"
open theMsg
end tell
Appreciate any ideas. Thanks!

Related

Select mailbox for Microsoft Outlook when using Applescript

I'm using Applescript to automatically draft and send emails in Microsoft Outlook. While everything is working as expected to send emails from my own account, I want to adjust the script to send emails from a different account that I have access to in Outlook. I've found this post, but the approach shown there generates an error for me.
https://macscripter.net/viewtopic.php?pid=185222#p185222
How can I adjust the script below to select the correct mailbox to send my email from? When I use the script below, the following error is generated when I attempt to save it.
Syntax Error
Expected class name but found identified
I've Google this error message, but haven't been able to find anything relevant to my task of changing the account the email is sent from.
set theAccount to the first exchange account whose name is "second.account#company.com"
set recipientAddress to "first.last#company.com"
set theSubject to "This is only a test"
set theContent to "<html><body><p>This is only a test.</p></body></html>"
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {account:theAccount, subject:theSubject, content:theContent}
tell newMessage
make new recipient at newMessage with properties {email address:{address:recipientAddress}}
end tell
save in drafts
end tell

Apple script: How to get the message id of the currently selected message in outlook app

I want to get the message id of the message currently open in outlook app during read mode in inbox on my mac using osa script.
so far I have tried this:
tell application "Microsoft Outlook"
set currentMessage to selection
set header to headers of currentMessage
end tell
And I got a response but headers do not have the message id
Mac OS Bir Sur, Apple M1
Outlook 16.46 Microsoft 365 subscription.
you should be able to:
get id of currentMessage
Works on Mojave with Outlook 16.44. (Exchange acct)
-- This works here:
tell application "Microsoft Outlook"
set currentMessage to selection
set thisID to id of currentMessage
get subject of message id thisID --> "test 1"
end tell

Outlook API, Message Moved to "Sent Items" still beign marked as "[Draft]"

I'm working on an Outlook Add-in, using office.js, where users can send secure emails using backend service.
In compose mode, when the user sends the email, using the add-in of course, the add-in will then move the message to "Sent Items" folder using the Outlook API /message/{id}/move and everything goes OK with the exception that the message in question still being marked as "Draft" by Outlook which is really annoying and does confuse the user who just sent the email by telling him that "this message hasn't been sent"
I searched through the API to see if there is a way to mark an email as "SENT" in order to prevent Outlook from showing this RED hint but with no luck so far!
So, My Question Is: Is there any way to overcome this misleading msg by marking the email as it was sent by Outlook?
Thanks in advance.
Finally, I was able to achieve a perfect solution for this challenge.
Based on:
#BrianClink's comment
This answer (Which uses Graph API but Outlook REST API): Microsoft Graph API mail office 365: Is any option create inbox message NOT as Draft?
The approach/steps I followed to mark a mailItem as "SENT" (and not shown as 'draft') and put it in "SentItems" Folder are as follow:
First, Save the mailItem as "draft" using Office.context.mailbox.item.currentMail.saveAsync then retrieve its ID
Clone this draft mailItem properties eg: 'Sender', 'Subject', 'Body', 'ToRecipients'..etc so you get an exact copy of it.
With the newly cloned mailItem, add '[SingleValueExtendedProperties]' property with this value :
[
{
PropertyId: 'Integer 0x0E07',
Value: '1'
}
];
Serialize the new item as JSON and POST it to "sentitems" folder as follows:
xhr.open('POST', restHost + '/v2.0/me/MailFolders/sentitems/messages/');
xhr.send(clonedEmailJson);
On success, with xhr.status=201 [created], Remove the draft mailitem using a [DELETE] request
And you will end up having a new mail item created in your "sentItems" folder which appears as it was sent by Outlook :)
This was a very helpful solution to me because my users are using my add-in to send secure emails (using 3rd party API) and NOT Outlook, So, I wanted them to have the same UX/feeling as when they use Outlook.
Note:
Although the solution worked for me perfectly, it came with a price!
On slow internet connections or in case emails containing large attachments, the process can be remarkably slow, because the addin will first save the draft to the remote Exchange Server, get its ID, then duplicate it and send it again to the server, then remove the draft-ed one.

Send iMessage to group chat

How can you send a iMessage to a group chat? I have searched everywhere and I can't find anything. I want to send it to a group chat named something, possibly If I get a list of buddies in the chat I can send it to everyone at once? A problem may be that I'm also in the chat, so that might be a problem.
To send to an existing group chat, you will need to obtain the chat's internal guid. There are 2 methods of doing this.
Extract it from the messages.app internal database, located on disk at ~/Library/Messages/chat.db. It is the guid column under the chat table. If you have the group chat named it will be easy to find by display_name.
You can use an AppleScript handler for Messages with the on chat room message received handler to capture the ID when someone posts in that chat.
Once you have the guid (should in a format similar to iMessage;+;chat831551415676550949), you can use AppleScript to send the message.
tell application "Messages"
set myid to "iMessage;+;chat831551415676550949"
set mymessage to "Hello World"
set theBuddy to a reference to text chat id myid
send mymessage to theBuddy
end tell
To send an image, replace the mymessage text with:
set ImageAttachment to POSIX file "File path here" as alias

Is there a way to find an email message from Outlook inbox via InternetMessageId via C#?

I have an InternetMessageID for an email item. I'd like to open a Reply email dialog to an email with this InternetMessageID. How can I find the email from Outlook API by InternetMessageID?
Internet message id as in "Message-ID" MIME header? Use Items.Find/FindNext or Items.Restrict to search for the PR_INTERNET_MESSAGE_ID (DASL name http://schemas.microsoft.com/mapi/proptag/0x1035001F) property.

Resources