VB.Net Outlook 2010 Add in How to Listen To Inspector Close Event (Mail Item)

扶醉桌前 提交于 2019-12-25 03:14:49

问题


I am not a developer in VB.Net Office Add in

I was trying to Develop a Small Adding for my Small Team

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.,

How can i replace Back the original Mail so that that window doesn't come

Or how to Discard the Message "Do you want to Save this email.."

Here Till now what i have written

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

Please Help me

EDIT

Please see here

I don't want this message to be displayed can some one direct me to correct code please


回答1:


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.,

You need to call the Save method which saves the Microsoft Outlook item to the current folder or, if this is a new item, to the Outlook default folder for the item type.

Also I'd recommend releasing all underlying COM objects instantly. Use 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 article.



来源:https://stackoverflow.com/questions/29006948/vb-net-outlook-2010-add-in-how-to-listen-to-inspector-close-event-mail-item

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