简体   繁体   English

在Redemption Powershell中发送邮件替代方法

[英]Sending mail alternative in Redemption Powershell

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. 我正在编写一个脚本,该脚本允许我通过当前的Outlook客户会话发送邮件,以便通过交换服务器具有合法性。 I have found some various methods like Send-MailMessage and whatnot, but they don't seem to pass due to policy reasons. 我发现了诸如Send-MailMessage类的各种方法,但由于策略原因它们似乎未通过。 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. 因此,我找到了一种从当前的Outlook客户会话中制作邮件项目的方法,但似乎无法访问以下字段:发件人(姓名,地址),收件人。

Also My code doesn't seem to be allowed to use Send() method. 另外,似乎不允许我的代码使用Send()方法。

The Code: 编码:

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

The Error: 错误:

在此处输入图片说明

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. 我知道我无法读取某些具有我所使用的Outlook版本内的安全补丁程序的常见Outlook对象原因的字段。 So I was forced to use Outlook-Redemption library to be allowed to play with these fields. 因此,我被迫使用Outlook-Redemption库被允许使用这些字段。

Do you think it's possible to do this exact function, but with the Redemption-object? 您是否可以使用Redemption对象来执行此确切功能? 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. 如果是这样,请帮助我或告诉我,使用合法的Outlook客户会话对象时,对于Redemption中的确切内容,powershell语法应是什么样子。

Thanks. 谢谢。

Try something like the following (off the top of my head): 尝试以下操作(不在我的头上):

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM