Powershell 在新电子邮件事件上调用 Web 服务 (Exchange 2010)

发布于 2024-08-31 22:12:50 字数 242 浏览 5 评论 0原文

我有 Exchange 2010,并且需要使用 Web 服务对进入邮箱的每封新电子邮件运行一个进程。该过程基本上会将电子邮件添加到内部任务列表中。

我可以为此使用 Powershell 吗?

之前从未使用过 Powershell,我并不真正了解它的功能。

如果没有,除了每 X 秒监控邮箱之外,任何人都可以建议另一种方法来执行此操作。我真的希望它基于事件,所以如果没有新邮件,则不进行处理。

干杯, 麦克风

I have Exchange 2010 and I need to run a process using web services against every new email to come in to a mailbox. The process will basically add the email to an internal task list.

Can I use Powershell for this?

Having never used Powershell before I don't really have a clue on it's capabilities.

If not can anyone suggest another way of doing this other than monitoring the mailbox every X seconds. Really I'd like it event based so if no new mail then no processing.

Cheers,
Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

信仰 2024-09-07 22:12:50

我花了几天时间研究这个问题,似乎很难将自定义代码添加到传入电子邮件事件中。如果 Exchange 认为它正在减慢电子邮件系统的速度,那么许多实现此目的的方法就会被忽略。 (http://www.outlookcode.com/article.aspx?id=62)

另一种方法是挂钩 SMTP 事件,这种方法可以工作,但感觉有点黑客攻击。为此,您需要编写一个脚本,然后针对电子邮件到达事件进行注册。

下面是一个示例 vb 脚本,用于向通过 SMTP 发送的每封电子邮件添加随机十六进制引用。

<SCRIPT LANGUAGE="VBScript">

Sub IEventIsCacheable_IsCacheable()
    'To implement the interface, and return S_OK implicitly
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
    Dim Flds

    randomize()

    set Flds = Msg.Fields
    With Flds
        strSubject = .Item("urn:schemas:httpmail:subject")

        if instr(strSubject, "Ref=") = 0 then
            strSubject = Replace(strSubject, CHR(9), "") & " (Ref=" & hex(replace(timer(), ".", "")) & hex(rnd()) & ")"
            .Item("urn:schemas:httpmail:subject") = strSubject
            .Update
        else
            strSubject = LEFT(strSubject, instr(strSubject, "(Ref=") - 1) & MID(strSubject, instr(instr(strsubject, "(Ref="), strSubject, ")") + 1, Len(strSubject)) & " (Ref=" & hex(replace(timer(), ".", "")) & hex(rnd()) & ")"
            .Item("urn:schemas:httpmail:subject") = strSubject
            .Update
        end if
    End With

    Msg.Datasource.Save

    EventStatus = 0 'Run next sink

End Sub

</SCRIPT>

然后运行这个来注册脚本。

Cscript smtpreg.vbs /add 1 onarrival SMTPAddRef CDO.SS_SMTPOnArrivalSink "mail from=*"
Cscript smtpreg.vbs /setprop 1 onarrival SMTPAddRef Sink ScriptName "C:\ENTERPATH\SMTPRef.vbs"

要取消注册脚本,请运行以下命令;

cscript smtpreg.vbs /remove 1 onarrival SMTPAddRef

最有弹性的方法似乎是创建一个基于计时器的系统,每 X 分钟检查一次新邮件。

不像我希望的那么光滑,但它会做。

希望这对其他人有帮助。

I have spent a few days looking into this and it seems that it's very difficult to add custom code to an incoming email event. And many of the methods of doing it will just get ignored if Exchange thinks it's slowing down the email system. (http://www.outlookcode.com/article.aspx?id=62)

The other method is to hook into the SMTP events which works but feels at bit of a hack. To do that you need to write a wscript then register that against the event of arrival of an email.

Here is an example vb script for adding a random hex reference onto every email which comes via SMTP.

<SCRIPT LANGUAGE="VBScript">

Sub IEventIsCacheable_IsCacheable()
    'To implement the interface, and return S_OK implicitly
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
    Dim Flds

    randomize()

    set Flds = Msg.Fields
    With Flds
        strSubject = .Item("urn:schemas:httpmail:subject")

        if instr(strSubject, "Ref=") = 0 then
            strSubject = Replace(strSubject, CHR(9), "") & " (Ref=" & hex(replace(timer(), ".", "")) & hex(rnd()) & ")"
            .Item("urn:schemas:httpmail:subject") = strSubject
            .Update
        else
            strSubject = LEFT(strSubject, instr(strSubject, "(Ref=") - 1) & MID(strSubject, instr(instr(strsubject, "(Ref="), strSubject, ")") + 1, Len(strSubject)) & " (Ref=" & hex(replace(timer(), ".", "")) & hex(rnd()) & ")"
            .Item("urn:schemas:httpmail:subject") = strSubject
            .Update
        end if
    End With

    Msg.Datasource.Save

    EventStatus = 0 'Run next sink

End Sub

</SCRIPT>

Then to register the script run this.

Cscript smtpreg.vbs /add 1 onarrival SMTPAddRef CDO.SS_SMTPOnArrivalSink "mail from=*"
Cscript smtpreg.vbs /setprop 1 onarrival SMTPAddRef Sink ScriptName "C:\ENTERPATH\SMTPRef.vbs"

To unregister the script run the follow;

cscript smtpreg.vbs /remove 1 onarrival SMTPAddRef

The most resilient method seems to be to create a timer based system to check for new mails every X minutes.

Not as slick as I was hoping for but it'll do.

Hope this helps others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文