views:

41

answers:

2

Hi, I have a .msg file on my filesystem. With powershell I can open a Outlook window with the message simply like this:

Invoke-Item "MY MAIL.msg"

How to change the subject and forward it to a given address via Powershell?

Thanks in advance

+1  A: 

You could try something like this, works with outlook 2010

$ol = New-Object -comObject Outlook.Application 
gm -InputObject $ol
$mail = $ol.Session.OpenSharedItem("C:\Users\fred\Desktop\Test Email Subject.msg")
$mail.Forward()
$Mail.Recipients.Add("[email protected]") 
$Mail.Subject = "Test Mail" 
$Mail.Body = " Test Mail 22222 "
$Mail.Send() 
Iain
hi, it works but i get some annoying security pop-ups and messages from outlook that make using this script useless for my purpose as i need to mass-forward some thousands of email
pistacchio
I dont get that warning in outlook 2010, but i know the warning you are talking about, in previous outlook interop work i did, i tried implementing a security shim, but never got it workinghttp://msdn.microsoft.com/en-us/library/aa140152%28office.10%29.aspxHope this helps
Iain
A: 

In PowerShell 2.0 there is a Send-MailMessage cmdlet that allows you to attach files, specify a subject and a recipient e.g.:

Send-MailMessage -smtpServer smtp.doe.com -from '[email protected]' `
                 -to '[email protected]' -subject 'Testing' -attachment foo.txt

Not sure how that plays with .msg files but you might give it a try.

Keith Hill