Applescript to get body of a message in Outlook 2011 - email

I need to use applescript to process the body of an email during incoming.
How can I get the body of an email when using Outlook 2011?
I am totally new to Applescript.
Any tutorial for using Applescript with Outlook 2011 or starter code for this question would be greatly helpful.

set theText to string
tell application "Microsoft Outlook"
set messages to selection
repeat with this_message in messages
set theText to content of this_message
end repeat
end tell
Now theText has the contents of the message.

Related

Script with every Incoming email

I am new to applescript and I am running into an issue.
I have setup a rule in mail to check incoming mails and trigger a script. What do I need to change in the script below ? The problem is in the script not the rules.
The script will not go beyond what I have below until I select it myself.
What would be the right code so I don't have to actually select the email.
Thanks.
tell application "Mail" -----check mail for incoming emails
set theMessage to message 1 of mailbox "INBOX" of account "GMAIL"
set thebody to content of theMessage
set theSelection to selection
set theMessage to item 1 of theSelection
content of theMessage
end tell
The basic syntax for a mail rule is
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with aMessage in theMessages
set thebody to content of aMessage
-- do other things with aMessage
end repeat
end perform mail action with messages
end using terms from
The script must be saved in ~/Library/Application Scripts/com.apple.mail/, then you are able to select it in the dialog window to create and edit a rule.
If I understand what you are asking, you just need to add the following lines to vadian's answer (replacing "-- do other things with aMessage")
set myword1 to the first word of body
set myword2 to the second word of body
There are lots of good resources for learning AppleScript at MacOSX Automation
Thanks for your help.
I guess that was what I needed at the time.
I found a workaround by just having Automator mark the message as read.
That did the trick to trigger my script automatically as soon as the message comes in.

Determines .msg attachment is opened in outlook window

Is there a way to determine whether or not a mail message that is opened in outlook window is a .msg attachment? I couldn't find anything usefull in the Outlook.MailItem object.
In other words, I have a mail item that has a .msg attachment in it.
Outlook opens a seperate message window when I double-clicked on the .msg attachment. The question is, is there a way to know whether or not the message is an attachment?
Thank's in advance.
Cheers,
Inoel
There is no reliable way to do that - you can check if MailItem.EntryId is empty, but it is also empty for the brand new unsaved messages. You can also check if MailItem.Sent is true. I don't know if there can be other cases when a message is sent yet does not have an entry id.

Sharepoint: use mailto command to send subject and body

I am developing in SharePoint and I would like to prepare a mailto command but I would like to send two values to the email and not just one. Normally in html the command works
Email
But in SharePoint I seem to only be able to send the first section after the email#here.com?. Depending on what I position first, I sometimes get the #Body field to go through or the #Title to go through. It appears that for some reason the "&" isn't accepted. I also tried %26 in the place of & with no result.
What is the best method to get both (body and subject) to go through to the mail-client?
Thank you in advance for your time, any guidance will be greatly appeciated

Apply an AppleScript to a Specific Email Message in Mail

I have an AppleScript I want to apply to individual emails (to archive them as PDFs with a particular file name), ut can't work out how to apply it to specific emails.
I can't set up a mail rule to run the script as it is just my judgment as to whether I want to archive one out of Mail or not. Have tried setting it up as a Service, but there is no Services menu on right clicking an email in Mail.
Any suggestions?!
Rich
How are you planning on specifying which individual emails? If by selecting them manually, you can “get selection”. Here’s a simple script that will get the subject and message Id of each selected message.
tell application "Mail"
set mySelection to get selection
set eMails to {}
repeat with selectedMessage in mySelection
set messageId to selectedMessage's message id as string
set eMail to selectedMessage's subject & ": " & messageId
tell me to set end of eMails to eMail
end repeat
set AppleScript's text item delimiters to "\n\n"
set the clipboard to (eMails as string)
end tell
Save it in ~/Library/Scripts/Applications/Mail/ and it will show up in your Scripts menu. You may have to go to AppleScript Editor’s settings to “Show Script menu in menu bar” to make the Scripts menu show up.
(Note: when you compile this script, the \n\n will turn into new lines.)

Open Lotus Notes mail page without sending from .NET

I'd like to open a new email page, in Lotus Notes (I know I know, I hate it too...) from a WinForm (.NET) application. Right now, I have found this that uses Interop.Domino.dll very useful. I adapted it a little and it works. Unfortunately, I don't want the email to be sent. I just need to open a new mail window with the body I give it, but no "To adress"...
I know Notes question don't have a high reply rate over here, but I give it a try anyway.
Thanks !
On Windows Notes clients greater than version 6, there is support for a Notes:\ URL scheme to launch documents. You can construct a URL dynamically in .Net that points to the user's mail database and opens a new mail form.
http://www.dominoguru.com/pages/LotusNotes_notesURLs.html has more details, but essentially it is of the form Notes:\server\database\0\memo?OpenForm
Any reason you can't just use a mailto call in your code? Assuming that Lotus Notes is the registered mail handler on the client system, you should be able to pass in the body attribute and wot-not…
The Lotus Domino Objects (Interop.Domino.dll) don't have access to the Notes UI. You would need to use the deprecated, late-bound Lotus Notes Automation classes. Warning: they're crashy, which is one of the reasons they've been deprecated for more than ten years (since the release of Lotus Notes and Domino R5.0.2c).
I finally did use the mailto. Here the code :
Public Shared Sub OuvrirNouveauMessage(ByVal destinataire As String, ByVal sujet As String, ByVal corpsCourriel As String)
Dim sFile As String = "mailto:" & destinataire & _
"?subject=" & sujet & _
"?body=" & corpsCourriel
If sFile.Length > 2050 Then
sFile = sFile.Substring(0, 2050)
End If
System.Diagnostics.Process.Start(sFile)
End Sub