使用EWS托管api在Exchange中收到电子邮件时自动触发操作

时间:2018-07-19 09:10:17

标签: vb.net exchange-server exchangewebservices

在我们的团队中,我们决定将收到的发送到投诉电子邮件地址的电子邮件保存在SQL数据库中,以便在仪表板中显示它们。 经过一些搜索后,我找到了以下解决方案,将其实现为visual studio,可以连接到我们的交换机并获取必要的数据。

Dim subject = ""    
Dim service As New ExchangeService(ExchangeVersion.Exchange2013_SP1)

'credentials

service.Credentials = New WebCredentials("complaints@blabla.com", "password")
service.Url = New Uri("https://teamWebmail.blabla.com/ews/Exchange.asmx")        
Dim inbox = Folder.Bind(service, WellKnownFolderName.Inbox)

For Each item As EmailMessage In service.FindItems(WellKnownFolderName.Inbox, New ItemView(3))
    ' here we save the data in sql database
    subject = subject + "<br>" + item.Subject
Next    
labelTest.Text = subject

现在,我已经在单击按钮时运行了此代码,它已成功运行;应该怎么做,或者我必须在哪里实现这种代码的和平性,以便每当收到电子邮件时,该函数就会运行并自动将数据保存在SQL DB中?

0 个答案:

没有答案