【问题标题】:VB.Net Outlook 2010 Add in How to Listen To Inspector Close Event (Mail Item)VB.Net Outlook 2010 添加如何收听 Inspector 关闭事件(邮件项目)
【发布时间】:2015-05-14 10:37:23
【问题描述】:

我不是 VB.Net Office Add in 的开发人员

我正在尝试为我的小团队开发一个小添加

我面临的问题是当我打开 MAIL(邮件项目)时,我能够从网站添加我想要的数据 现在,当我关闭邮件时,它会显示 您是否要保存此邮件等,

我怎样才能把原来的邮件替换回原来的邮件,这样那个窗口就不会出现了

或者如何丢弃消息“你想保存这封电子邮件吗..”

到这里为止我写的东西

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

请帮帮我

编辑

请看这里

我不希望显示此消息,请有人指导我更正代码

【问题讨论】:

    标签: vb.net visual-studio-2010 email outlook


    【解决方案1】:

    我面临的问题是,当我打开邮件(邮件项目)时,我可以从网站添加我想要的数据现在当我关闭邮件时,它会显示您是否要保存此邮件等,

    您需要调用 Save 方法将 Microsoft Outlook 项目保存到当前文件夹,或者,如果这是一个新项目,则保存到项目类型的 Outlook 默认文件夹。

    我还建议立即释放所有底层 COM 对象。使用完后,使用System.Runtime.InteropServices.Marshal.ReleaseComObject 释放 Outlook 对象。然后在 Visual Basic 中将变量设置为 Nothing(在 C# 中为 null)以释放对对象的引用。您可以在Systematically Releasing Objects 文章中了解更多相关信息。

    【讨论】:

    • 感谢您抽出宝贵时间回复,当我尝试关闭它询问我不想显示的问题时,请检查我发布图像的原始消息
    • 您是否尝试在对 Mail 项目对象进行修改后调用 Save 方法?
    • 然后您需要关闭 Inspector 窗口并放弃任何更改。 Close 方法允许完成这项工作。将 false 作为参数传递。
    • 感谢 Eugene 的想法 :) 我昨天想通了,我将这个 Outlook.OlInspectorClose.olDiscard 传递给 close 方法,感谢您的所有回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多