Scripting Office Outlook 2016 on Mac [closed] - vba

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'd like to automate Outlook 2016 on Mac.
The task I'd like to automate is basically the following:
search inbox for mails from the previous week having a specific
pattern in the title
prepare a new mail which content is the consolidated content of all
the mails found in the previous step
let the mail open (or in draft) to let me edit it before to send it
Well, I just don't know how to handle it...
Visual Basic (my preferred option) seems not to be present at all
in Outlook 2016 on Mac!! I can't even find the VB editor (while I
do find it for e.g. excel).
AppleScript might allow to do that. But I just do not find any
documentation on the outlook API. Plus, it seems to only allow very
basic automation.
Automator?
Note that I have access to a windows machine. So, it is possible (though painful) for me to write a VBA script there and "transfer it" to the Mac.
I do not have Office 365.
Thanks for your help!
Sylvain

This is very possible with AppleScript. Here's an example with the basics:
tell application "Microsoft Outlook"
set theContent to ""
set theMessages to messages of folder "Inbox" of default account
repeat with theMessage in theMessages
if subject of theMessage contains "match this string" then
set theContent to theContent & plain text content of theMessage
end if
end repeat
set theMessage to make new outgoing message with properties {subject:"the subject line", plain text content:theContent}
make new recipient with properties {email address:{address:"recipient#somewhere.com", name:"Lumpkin Skinbark"}} at end of to recipients of theMessage
open theMessage -- for further editing
end tell
If you haven't found it yet, you can open Outlook's script dictionary by choosing "Open Dictionary" from the File menu and selecting the Microsoft Outlook application.

Related

How to apply Azure Information Protection labels to an Outlook email using Access VBA?

I have a VBA function in our MS Access database that generates Outlook emails and sends them from a shared inbox.
Our company uses Azure Information Protection to protect documents. A label needs to be applied to each email before it is sent (e.g. Public, Business Sensitive, Internal).
Rather than having the user click the label 25 times as it pops up for each email, I am trying to apply it programmatically.
I get error code (-1248837627).
My solution was to grab the labels GUID and then apply it to the email as below. I came across other solutions such as using SendKeys but I prefer it to be a last resort.
With olMail
.To = olSendTo
.Subject = olSubject
.PermissionTemplateGuid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX"
.Permission = olPermissionTemplate
'And so on, the email function works great until the above two lines are added
Am I applying the .Permissions or .PermissionTemplateGUID improperly?
I have seen a similar approach to apply labels to Excel documents (grabbing and setting the guid).
The code you posted is used to specify Information Rights Management (IRM) permissions. Azure Information Protection is another story.
You need to add a user property in the following format:
"MSIP_Label_" & guid_internal_use_only & "_Enabled"
But I'd suggest exploring internals of Outlook mail items using MFCMAPI or OutlookSpy to find the exact solution. Try to set it manually then explore internals using these tools.

Outlook VBA - How to get email item from user input

Although Im quite experienced with Excel VBA, Im not so much in regards of Outlook VBA (started yesterday, literally), so Im uncertain on how to get this simple task accomplished:
I created some coding to get a specific e-mail from the Inbox and then parse it and forward - that part is all good and well. Currently the code autodetects and retrieve the e-mail item using a set of parameters to filter through the Inbox. However, now I need to expand this code so that it can work with any e-mail item, and not only with that specific e-mail.
My idea is to get the user to input which e-mail item he/she wants to parse and forward, instead of getting the code to look in a specific place. How can that be done? The user input methods that I use regularly are InputBox (which returns a string) and GetOpenFileName, none of them suitable to pointing to a mail item within Outlook.
I thought about making the code work with the currently open e-mail item, but often the users have several e-mail items opened at once - forcing them to leave only one open for the code to work is not viable. Also, the code will be ran by people who have little to no IT expertise, so requesting things such as paths is also not an option. Is there any method for this?
I figured that working with Active MailItem is the way to go, as #niton suggested as well. I used a coding very similar to the one in this post, although I had to develop the handlers in case the user has other types of Objects active at the moment (AppointmentItems, for instance) or have multiple items selected. Final solution wasn't that much elegant - I was wishing for some sort of system input box where the user could point to the mail or something, but this works.

How to search unread mail in Outlook with VBScript? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am able to open Outlook, focus it to the inbox folder, and count unread mails with .Unread.
I would like to be able to search unread email for a particular email address in the body of the emails.
I am using Windows 7 with Outlook 2007.
You need to use the Restrict or Find/FindNext methods of the Items class. Take a look at the following articles for the sample code and more information about them:
How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
How To: Use Restrict method to retrieve Outlook mail items from a folder
For example, to find all unread emails in the folder you can use the following search criteria:
[UnRead] = true
Also you may find the AdvancedSearch method of the Application class helpful. The key benefits of using the AdvancedSearch method in Outlook are:
The search is performed in another thread. You don’t need to run another thread manually since the AdvancedSearch method runs it automatically in the background.
Possibility to search for any item types: mail, appointment, calendar, notes etc. in any location, i.e. beyond the scope of a certain folder. The Restrict and Find/FindNext methods can be applied to a particular Items collection (see the Items property of the Folder class in Outlook).
Full support for DASL queries (custom properties can be used for searching too). You can read more about this in the Filtering article in MSDN. To improve the search performance, Instant Search keywords can be used if Instant Search is enabled for the store (see the IsInstantSearchEnabled property of the Store class).
Finally, you can stop the search process at any moment using the Stop method of the Search class.
The Outlook object model provides three main ways for working with item bodies:
Body - a string representing the clear-text body of the Outlook item.
HTMLBody - a string representing the HTML body of the specified item.
Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.
You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to customize the message body.

VBA Edit SharePoint Discussion Post (PostItem) and Update Web Discussion

I have a SharePoint discussion board sycned to Outlook 2010.
I want to be able to programmatically modify my posts within a SharePoint Discussion Board within Outlook VBA and have these changes reflected on the online discussion board.
The below code works in a test case to modify the items on the Outlook side but it is not synchronizing with SharePoint.
Private Sub modifySharePointItem()
Dim obj As Outlook.PostItem
Set obj = Application.ActiveExplorer.Selection.item(1)
obj.Body = obj.Body + "test addition"
obj.Save
obj.Post
End Sub
I am assuming I need to not just Save and Post but an additional "synchronize" type command but I do not know what it is.
Reading about the data model for PostItem was basically useless unfortunately and none of the methods seemed to do what I was interested in.
I found out (by accident.....) I am able to delete posts from Outlook - so I can obviously get much of the way here, but I still am unsure how to sync the lists when items are modified.
You can use the Client Object Model to do modifications and editing in Sharepoint. I do it all the time. Since Outlook 2010 compiles down to the CLI you could use the Client Object Model dlls to do what you need. I have a whole bunch of C# code that I could share if you need it. This is what I used to get started.
http://msdn.microsoft.com/en-us/library/ee537247(v=office.14).aspx
I hope that helps!

How to determine where a Mailitem is being opened from in Outlook 2007 using VSTO 2005 SE

I have an Outlook 2007 Add-in in VSTO 2005 SE that allows users to save e-mails into our document management system. From within our system users are able to open e-mails they have previously saved. However, when doing so I need to try and prevent them from saving them again.
I am trying to figure out how to determine if the Mailitem being opened is coming from the Outlook e-mail client or from an external source.
I know that normally the EntryId Property of the Mailitem is null or empty string when a Mailitem has not been previously saved in Outlook, however, it seems like when a Mailitem is being opened from within our system the EntryID is not null.
Adam,
Normally most DM systems set mapi properties or user properties on the mail items as they get saved ... DOCID etc. from the DM system. I would get outlook spy and hunt around on the DM emails to try and find this Property. Then you will be able to test for that in your VSTO add in. Failing that, may be you can explain how you open the email from you DM system is from inside outlook via a DM plug in ? or is it totally external app?
What DM System is it ?
Marcus