0
votes

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.

The Code:

$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace("MAPI")

$mail = $ol.CreateItem(0)

$Mail.To = "[email protected]"
$mail.Subject = "Some subject"
$mail.Body = "Some body, look at attachment"
$mail.Attachments.Add("<path>")

$mail.Send()

The Error:

enter image description here

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.

2

2 Answers

1
votes

Try something like the following (off the top of my head):

$safeitem = New-Object -ComObject Redemption.SafeMailItem
$safeitem.Item = $mail
$safeitem.Send() 
0
votes

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()