tell application "Microsoft Outlook"
set theContent to "Mail Content etc."
set theMessage to make new outgoing message with properties {subject:(("Month ") & (do shell script "date '+%m'")), content:theContent}
make new recipient with properties {email address:{address:"to@mail.com"}} at end of to recipients of theMessage
make new recipient with properties {email address:{address:"to@mail.com"}} at end of cc recipients of theMessage
open theMessage
end tell
This script works fine. I like to add a line that picks one of several pop accounts I have so it sends it form that one. I tried inserting at the end
Select the sending account manually and then have a script ‘get sender…’. This should provide the required syntax. If it doesn’t match up, ‘get properties’ of the message and see which property aligns with the desired account. I can’t help but wonder if ‘sender’ only applies to inbound messages, which is the case for some of the message properties.
And FWIW, you don’t really send from an email address. You send from an account, which probably has an address (and technically, it isn’t a pop account, it’s smtp).
Assuming the above doesn’t work… if outlook is getting the sender from among your accounts, try referencing the account rather than the email address (or maybe the address of the account).
p.s. Saying it doesn’t work is rarely helpful. What happens? Is there an error message? If so, what is it?
Thanks folks. helpful cpmments and so I figured it out.
tell application "Microsoft Outlook"
set theMessage to make new outgoing message with properties {sender:{name:"Name", address:"mail@name.com"}, subject:(("Month ") & (do shell script "date '+%m'")), plain text content:"Hallo there"}
tell theMessage
make new to recipient with properties {email address:{address:"mail@mail.com"}}
end tell
send theMessage
end tell
I have another question. I like the subject to be last month. So if I send it in month 11 I like the subject to say month 10. My shell script works for the current month but not putting in last month. Any ideas? An other solution?
PS. and yes I do not like Outlook either but that is what I am stuck with.
use scripting additions
set myDate to current date
set monthForSubject to PreviousMonth(myDate)
on PreviousMonth(anyDate)
set myMonth to month of (anyDate) as integer
set month of anyDate to (myMonth - 1)
return month of anyDate as text
end PreviousMonth
The -v option allows you to adjust the date/time, either backwards or forwards (change - to + after the v) by the amount after the sign, and of the units expressed by the letter (e.g. y, m, w, d, H, M or S). Further details can be found in date’s man page.
return previousMonth(current date) as text -- or as integer.
on previousMonth(anyDate)
return (month of (anyDate - (anyDate's day) * days))
end previousMonth
tell application "Microsoft Outlook"
set theMessage to make new outgoing message with properties {sender:{name:"Name", address:"mail@name.com"}, subject:(("Month ") & (do shell script "date -v-1m '+%m'")), plain text content:"Hallo there"}
tell theMessage
make new to recipient with properties {email address:{address:"mail@mail.com"}}
end tell
send theMessage
end tell
Using vanilla AppleScript:
on previousMonth(anyDate)
return (month of (anyDate - (anyDate's day) * days))
end previousMonth
-- Get the number of the previous month as text, with a leading zero if applicable.
set lastMonth to text 2 thru 3 of ((100 + previousMonth(current date)) as text)
tell application "Microsoft Outlook"
set theMessage to make new outgoing message with properties {sender:{name:"Name", address:"mail@name.com"}, subject: ("Month " & lastMonth), plain text content:"Hallo there"}
tell theMessage
make new to recipient with properties {email address:{address:"mail@mail.com"}}
end tell
send theMessage
end tell
I’m assuming the Outlook-specific code is correct.
In general, and I’m being loose with my terminology here, objects (e.g. messages) have properties. If you open the applescript dictionary for an application, you can look up those myriad properties and see what they refer to.
As each application defines its own stuff, there is inconsistency in syntax. Sometimes, if you ask for the properties (i.e. get properties of …) of a properly set-up object, you can get a clue as to the syntax.
So in this case, create a message and set the sending account as desired. Then create a simple script that gets the properties of that message. With the message selected (in Drafts), if I run the following script, I will get a reference to the message:
tell application "Microsoft Outlook" to selection
--> outgoing message id 4 of application "Microsoft Outlook"
Now armed with a way to refer to the message, run a script like this:
tell application "Microsoft Outlook"
properties of outgoing message id 4
end tell
You’ll end up with a collection of properties along with their related values for the specified message. It might offer a clue as to how you can set them correctly.
My copy of Outlook isn’t activated (I only got Office for Excel) so I can’t actually set up an outgoing account, which means that numerous properties, including ‘sender’, are empty.
One challenge remains. It opens a new Mail with the correct sender address. However the signature that is set up in Outlook is not in that mail. If I open a new mail by hand the signature is there.
OK Folks I got the fix to getting the correct POP account, from a guy at a Swiss Mac forum.
It will be easy to integrate the month script above.
tell application "Microsoft Outlook"
set theAccount to the first pop account whose name is "The-name-of-the-account-you-want-to-use"
set theContent to "Mail Content etc."
set theMessage to make new outgoing message with properties {account:theAccount, subject:"Test", content:theContent}
make new recipient with properties {email address:{address:"to@mail.com"}} at end of to recipients of theMessage
make new recipient with properties {email address:{address:"to@mail.com"}} at end of cc recipients of theMessage
open theMessage
end tell
Thanks for your help.
PS Posted just in case anybody looks for this solution too.