Call Slack API via VBScript Rule in Outlook

时光怂恿深爱的人放手 提交于 2019-12-05 19:26:09

So I resolved this myself, but wanted to post more details.

Request : I want to make a call to Slack and update one of my channels with a custom message WHEN I receive an email and an Outlook rule is triggered (message from X and sent to Y).

Solution : First off, you need to navigate to selfcert.exe in your Microsoft Office folders on the C drive, create a new self-signed certificate, and then add that certificate to Trusted Publishers in Outlook. AFTER that's done, I opened Visual Basic from Outlook by pressing Alt+F11 and created the following script in the "ThisOutlookSession" project.

Sub ProcessSend(Item As Outlook.MailItem)
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")

    strEnvelope = "payload={""channel"": ""#edt-error"", ""text"": ""This is posted to #edt-error.""}"

    Call oXMLHTTP.Open("POST", "https://INSERT-YOUR-SERVICE-URL-HERE" & posFirm, False)
    Call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    Call oXMLHTTP.Send(strEnvelope)

    Dim szResponse: szResponse = oXMLHTTP.responseText
    Call oXMLDoc.LoadXML(szResponse)
End Sub

Finally I created a rule that looked for the appropriate parameters and then peformed a "Run this script" action. When you click on the "script" name in the rule, a window will popup and you can select the above script you already created.

Hope this is helpful to someone!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!