how to set sender in Outlook pop account

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

set sender to "xyz@xyz.com"

but that does not work.

Any idea as to how to do this?

I don’t like Outlook, so I don’t have it on my Mac. But have you tried instead of

set sender to "xyz@xyz.com"

this?

tell theMessage to set sender to "xyz@xyz.com"

A couple of suggestions…

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.

Try this:


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

% date ‘+%m’
→ 11

% date -v-1m ‘+%m’
→ 10

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.

Hi Ed.

It won’t work in January. This would be better:

return previousMonth(current date) as text -- or as integer.

on previousMonth(anyDate)
	return (month of (anyDate - (anyDate's day) * days))
end previousMonth

Good morning Folks and thanks for the help.

Nigel’s solution works but I can not figure out how to integrate it in the script so it uses it in the ‘subject’ line.

Sorry I am new to this and not a code guy at all.

Hi.

Using Mockman’s shell script:

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.

Hi NG

That works, thanks.

Hi Mockman, your answer did intrigue me. However I do not understand how to achieve what you suggest. Could you help me here?

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.

That works for me Mockman. Thanks. Learned something.

I get the following info:

{sender:{name:"My Name", address:"mymail@mymail.com", type class:unresolved address}

So in my originally pasted script, how would I use this so that it opens that account (and the footers that are in the signature), as a sender?

or am I asking you to much since yo do not have Outlook.

Just as it looks in Nigel’s latest post. I don’t think that you require the class to get what you need. You had it figured out.

Thanks.

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.

Any idea as to how to solve this?

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.