VB.Net Outlook 2010 添加如何监听检查员关闭事件(邮件项目)
VB.Net Outlook 2010 Add in How to Listen To Inspector Close Event (Mail Item)
我不是 VB.Net Office 插件中的开发人员
我正在尝试为我的小团队开发一个小插件
我面临的问题是当我打开 MAIL(邮件项目)时,我能够从网站添加我想要的数据
现在当我关闭邮件时它说 你想保存这封邮件等等,
我怎样才能替换回原来的邮件,这样 window 就不会来了
或者如何丢弃消息“你想保存这封电子邮件......”
到此为止我所写的
Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Public Class ThisAddIn
Dim WithEvents inspectors As Outlook.Inspectors
Dim WithEvents currentExplorer As Outlook.Explorer = Nothing
Public WithEvents myItem As Outlook.MailItem
Private Sub ThisAddIn_Startup(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Startup
inspectors = Me.Application.Inspectors
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
MsgBox("Yo", MsgBoxStyle.Information)
End Sub
Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
Dim mBody As String = mailItem.Body
Dim mFrom As String = GetSmtpAddress(mailItem).ToString()
Dim cec As String
Dim result As String
Dim itm As Object
'itm = Inspector.CurrentItem
Dim webClient As New System.Net.WebClient
If mFrom IsNot Nothing Then
cec = mFrom.Split(New Char() {"@"c})(0)
result = webClient.DownloadString("http://example.com/post.php?submit=1&name=" & cec)
Dim oAddin As New jsonparser(result)
If Not (mailItem Is Nothing) Then
If (mailItem.EntryID IsNot Nothing) Then
If (oAddin.GetProperty("team").Value IsNot "Doesn't Exists" OrElse oAddin.GetProperty("team").Value IsNot "You cannot access directly") Then
mailItem.Body = "[" & oAddin.GetProperty("team").Value.ToString() & "]" & vbCrLf & vbCrLf & vbCrLf & mBody
MsgBox(mailItem.Body)
End If
End If
End If
End If
Dim myOlInspectorClose = inspectors
'Dim myOlInspectorClose As Outlook.Inspectors
End Sub
Private Sub myOlInspectorClose_Close()
MsgBox("hey clsing")
End Sub
Private Function GetSmtpAddress2010(ByVal mItem As Outlook.MailItem)
Return mItem.Sender.GetExchangeUser().PrimarySmtpAddress
End Function
Private Function GetSmtpAddress(ByVal mItem As Outlook.MailItem)
'Dim mItem As Outlook.MailItem
Dim recip As Outlook.Recipient
Dim exUser As Outlook.ExchangeUser
Dim sAddress As String
If (mItem.SenderEmailType.ToLower() = "ex") Then
recip = Globals.ThisAddIn.Application.GetNamespace("MAPI").CreateRecipient(mItem.SenderEmailAddress)
exUser = recip.AddressEntry.GetExchangeUser()
sAddress = exUser.PrimarySmtpAddress
Else
sAddress = mItem.SenderEmailAddress.Replace("'", "")
End If
Return sAddress
End Function
End Class
请帮帮我
编辑
请看这里
我不想显示这条消息,有人可以指导我更正代码吗
The problem i am Facing is When i open the MAIL (Mail ITEM) I am able to Add my Desired Data from a website Now when i Close the Mail it says Do you want to Save this Message etc.,
您需要调用 Save 方法将 Microsoft Outlook 项目保存到当前文件夹,或者如果这是一个新项目,则保存到该项目类型的 Outlook 默认文件夹。
我还建议立即释放所有底层 COM 对象。使用 System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about that in the Systematically Releasing Objects 篇文章。
我不是 VB.Net Office 插件中的开发人员
我正在尝试为我的小团队开发一个小插件
我面临的问题是当我打开 MAIL(邮件项目)时,我能够从网站添加我想要的数据 现在当我关闭邮件时它说 你想保存这封邮件等等,
我怎样才能替换回原来的邮件,这样 window 就不会来了
或者如何丢弃消息“你想保存这封电子邮件......”
到此为止我所写的
Imports System.Runtime.InteropServices
Imports System.Text.RegularExpressions
Public Class ThisAddIn
Dim WithEvents inspectors As Outlook.Inspectors
Dim WithEvents currentExplorer As Outlook.Explorer = Nothing
Public WithEvents myItem As Outlook.MailItem
Private Sub ThisAddIn_Startup(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Startup
inspectors = Me.Application.Inspectors
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
MsgBox("Yo", MsgBoxStyle.Information)
End Sub
Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
Dim mBody As String = mailItem.Body
Dim mFrom As String = GetSmtpAddress(mailItem).ToString()
Dim cec As String
Dim result As String
Dim itm As Object
'itm = Inspector.CurrentItem
Dim webClient As New System.Net.WebClient
If mFrom IsNot Nothing Then
cec = mFrom.Split(New Char() {"@"c})(0)
result = webClient.DownloadString("http://example.com/post.php?submit=1&name=" & cec)
Dim oAddin As New jsonparser(result)
If Not (mailItem Is Nothing) Then
If (mailItem.EntryID IsNot Nothing) Then
If (oAddin.GetProperty("team").Value IsNot "Doesn't Exists" OrElse oAddin.GetProperty("team").Value IsNot "You cannot access directly") Then
mailItem.Body = "[" & oAddin.GetProperty("team").Value.ToString() & "]" & vbCrLf & vbCrLf & vbCrLf & mBody
MsgBox(mailItem.Body)
End If
End If
End If
End If
Dim myOlInspectorClose = inspectors
'Dim myOlInspectorClose As Outlook.Inspectors
End Sub
Private Sub myOlInspectorClose_Close()
MsgBox("hey clsing")
End Sub
Private Function GetSmtpAddress2010(ByVal mItem As Outlook.MailItem)
Return mItem.Sender.GetExchangeUser().PrimarySmtpAddress
End Function
Private Function GetSmtpAddress(ByVal mItem As Outlook.MailItem)
'Dim mItem As Outlook.MailItem
Dim recip As Outlook.Recipient
Dim exUser As Outlook.ExchangeUser
Dim sAddress As String
If (mItem.SenderEmailType.ToLower() = "ex") Then
recip = Globals.ThisAddIn.Application.GetNamespace("MAPI").CreateRecipient(mItem.SenderEmailAddress)
exUser = recip.AddressEntry.GetExchangeUser()
sAddress = exUser.PrimarySmtpAddress
Else
sAddress = mItem.SenderEmailAddress.Replace("'", "")
End If
Return sAddress
End Function
End Class
请帮帮我
编辑
请看这里
我不想显示这条消息,有人可以指导我更正代码吗
The problem i am Facing is When i open the MAIL (Mail ITEM) I am able to Add my Desired Data from a website Now when i Close the Mail it says Do you want to Save this Message etc.,
您需要调用 Save 方法将 Microsoft Outlook 项目保存到当前文件夹,或者如果这是一个新项目,则保存到该项目类型的 Outlook 默认文件夹。
我还建议立即释放所有底层 COM 对象。使用 System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about that in the Systematically Releasing Objects 篇文章。