I'm writing a script that allows me to send a mail via my current outlook client session so that it's legit to pass the exchange server. I have found some various methods like Send-MailMessage
and whatnot, but they don't seem to pass due to policy reasons.
So I found a way to make a mail item from the current outlook client session, but I can't seem to access fields such as: Sender(name, address), To.
Also My code doesn't seem to be allowed to use Send()
method.
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace("MAPI")
$mail = $ol.CreateItem(0)
$Mail.To = "user@mail.com"
$mail.Subject = "Some subject"
$mail.Body = "Some body, look at attachment"
$mail.Attachments.Add("<path>")
$mail.Send()
I don't know why this is happening, but I do think I know why I can't access certain fields. I know I can't read certain fields with common Outlook Object cause of a security patch within the outlook version I am using. So I was forced to use Outlook-Redemption library to be allowed to play with these fields.
Do you think it's possible to do this exact function, but with the Redemption-object? If so please help me or tell me how the powershell syntax should look like for this exact thing in Redemption, working with a legit outlook client session object.
Thanks.
This works with following code:
$mItem = $ol.CreateItem(0)
$mail = $routlook.GetRDOObjectFromOutlookObject($mItem)
$mail.To = "<recipient's address>"
$mail.Subject = "Some Subject"
$mail.Body = "Some body"
$mail.Attachments.Add("<path to attachment file>")
$mail.DeleteAfterSubmit = $True #delete's mail after sending
$mail.Send()