Reputation: 1
I'm attempting to get a Powershell V2 script open a new mail message window in the default mail app with the To, CC, Subject, and Body fields pre filled in. In a batch script I would simply use the mailto function, which works perfectly. However I can't make that work in Powershell and the Send-MailMessage cmdlet is asking for information that the user probably won't have.
The script will be used by multiple users, so I can't hardcode the sender/server information into the script; also the user needs to be able to make changes to the email message before it's sent.
Is there a cmdlet that will allow me to only fill in the four fields I mentioned before, open in the default mail app (however it's set in the system), and allow the user to make changes to the message before sending?
I've been searching for an answer for this for a month, with no success as of yet. Any assistance would be greatly appreciated.
Upvotes: 0
Views: 5790
Reputation: 81
I can confirm, that Mathias's syntax:
PS C:\> Start-Process "mailto:[email protected]?Subject=This is a Subject&[email protected]&Body=This is the contents of the message"
# Start-Process immediately returns but a new mail message is launched
works also with Thunderbird.
Upvotes: 1
Reputation: 174690
If you supply a URI with the mailto:
scheme to Start-Process
, Windows will automagically figure out the application associated with it (no matter whether that is Outlook, Thunderbird, Windows Mail or whatever you fancy) and launch it:
e.g.:
PS C:\> Start-Process "mailto:[email protected]"
# Start-Process immediately returns but a new mail message is launched
Just like any other URI, a mailto:
URI can have a query attached:
PS C:\> Start-Process "mailto:[email protected]?Subject=This is a Subject&[email protected]&Body=This is the contents of the message"
# The message is created with the above values in place (at least in Outlook)
Upvotes: 5