是什么导致Outlook双击“发送”按钮发送电子邮件?

时间:2019-02-18 08:10:11

标签: vb.net visual-studio plugins outlook add-in

我试图解决一个问题,即安装此插件后,Add-in Express会双击以在Outlook中发送电子邮件。

这是Windows 10系统,通过Visual Studio 2017社区和Add-In Express开发。我接手了一个非常老的项目,旨在为我们的DMS系统的Outlook添加一个插件。

The Project Structure

该插件是用VB开发的,尝试在Outlook上进行调试时控制台中没有响应或反馈。

/Common/SettingSer.vb

Imports System.Xml.Serialization
Imports System.IO

Public Class SettingSer
    Public Shared _filename As String = Constants.WEB_SERVICE_SETTING_SER_FILE
    Public _ADXOIFormSendOption As Integer
    Public _PathForm_Destination As String
    Public _PathForm_DirectoryID As Integer
    Public _PathForm_ExportTypeOption As Integer
    Public _PathForm_emailExport As Boolean
    Public _PathForm_attachmentExport As Boolean
    Public _PathForm_attachmentsUnderEmailSubjectDirectory As Boolean
    Public _PathForm_directUpload As Boolean
    Public _PathForm_ApplicationRawURL As String  '原来的服务器地址
    Public _PathForm_ApplicationNewURL As String  '指定的服务器地址

    Public _Profile_profileOptionsIndex As Integer
    Public _Profile_applyingToRemaining As Boolean
    Public _Profile_applyToAllChecked As Boolean

    Public _DefaultUploadFolder_SettingEnabled As Boolean
    Public _DefaultUploadFolder_Destination As String
    Public _DefaultUploadFolder_DirectoryID As Integer
    Public _DefaultUploadFolder_ExportTypeOption As Integer
    Public _DefaultUploadFolder_emailExport As Boolean
    Public _DefaultUploadFolder_attachmentExport As Boolean
    Public _DefaultUploadFolder_attachmentsUnderEmailSubjectDirectory As Boolean

    Public Shared Function LoadSettingFromXml() As SettingSer
        Dim stream As FileStream = Nothing

        Try
            Dim setting As SettingSer = Nothing
            If File.Exists(_filename) Then
                Dim info As FileInfo = New FileInfo(_filename)
                If info.Length > 0 Then
                    Dim xmlSer As New XmlSerializer(GetType(SettingSer))
                    stream = File.OpenRead(_filename)
                    setting = xmlSer.Deserialize(stream)
                End If
            End If

            Return setting
        Catch ex As Exception
            Throw ex
        Finally
            If Not stream Is Nothing Then
                stream.Flush()
                stream.Close()
            End If

        End Try
    End Function

    Public Shared Sub SaveSettingToXml(ByRef setting)
        Dim stream As FileStream = Nothing

        Try
            If Not Directory.Exists(Constants.APPLICATION_DATA) Then
                Directory.CreateDirectory(Constants.APPLICATION_DATA)
            End If

            Dim xmlSer As New XmlSerializer(GetType(SettingSer))

            stream = File.Open(_filename, FileMode.Create, FileAccess.Write)

            xmlSer.Serialize(stream, setting)

        Catch ex As Exception
            Throw ex
        Finally
            If Not stream Is Nothing Then
                stream.Flush()
                stream.Close()
            End If
        End Try
    End Sub

    Public Sub New()
        _ADXOIFormSendOption = 0
        _PathForm_Destination = ""
        _PathForm_DirectoryID = 0
        _PathForm_ExportTypeOption = 0
        _PathForm_emailExport = True
        _PathForm_attachmentExport = False
        _PathForm_attachmentsUnderEmailSubjectDirectory = False
        _PathForm_directUpload = False

        _Profile_profileOptionsIndex = 0
        _Profile_applyingToRemaining = False
        _Profile_applyToAllChecked = False


        _PathForm_ApplicationRawURL = ""
        _PathForm_ApplicationNewURL = ""

        _DefaultUploadFolder_SettingEnabled = True
        _DefaultUploadFolder_Destination = ""
        _DefaultUploadFolder_DirectoryID = 0
        _DefaultUploadFolder_ExportTypeOption = 0
        _DefaultUploadFolder_emailExport = True
        _DefaultUploadFolder_attachmentExport = False
        _DefaultUploadFolder_attachmentsUnderEmailSubjectDirectory = False
    End Sub
End Class

/Email/EmailAttachment.vb

Public Class EmailAttachment
    Inherits EmailContentsBody
    Private appendix As Outlook.Attachment
    Private shelteredDirectory As String
    Private attachmentOrder As Integer

    Public Sub New(ByVal letter As Outlook.MailItem, ByVal parent As Integer, ByVal order As Integer, ByVal itemIndex As Integer, ByVal underShelteredDirectory As Boolean, ByVal savedName As String, ByVal area As String, ByVal information As String, ByVal subsidiary As Outlook.Attachment, ByVal shieldingDirectory As String, ByVal attachmentSequence As Integer)
        MyBase.New(letter, parent, order, itemIndex, underShelteredDirectory, savedName, area, information)
        appendix = subsidiary
        shelteredDirectory = shieldingDirectory
        fileType = Constants.EMAIL_ATTACHMENT_FILE_TYPE
        attachmentOrder = attachmentSequence
    End Sub

    Public Sub New(ByVal letter As Outlook.ReportItem, ByVal parent As Integer, ByVal order As Integer, ByVal itemIndex As Integer, ByVal underShelteredDirectory As Boolean, ByVal savedName As String, ByVal area As String, ByVal information As String, ByVal subsidiary As Outlook.Attachment, ByVal shieldingDirectory As String, ByVal attachmentSequence As Integer)
        MyBase.New(letter, parent, order, itemIndex, underShelteredDirectory, savedName, area, information)
        appendix = subsidiary
        shelteredDirectory = shieldingDirectory
        fileType = Constants.EMAIL_ATTACHMENT_FILE_TYPE
        attachmentOrder = attachmentSequence
    End Sub

    Public Function getAppendix() As Outlook.Attachment
        Return appendix
    End Function

    Public Sub setAppendix(ByVal letter As Outlook.Attachment)
        appendix = letter
    End Sub

    Public Function getShelteredDirectory() As String
        Return shelteredDirectory
    End Function

    Public Sub setShelteredDirectory(ByVal shieldingDirectory As String)
        shelteredDirectory = shieldingDirectory
    End Sub

    Public Overrides Function getFileSize() As Double
        'getFileSize = Math.Round(appendix.Size / 1024, 2)
        getFileSize = 0
    End Function

    Public Function getAttachmentOrder() As Integer
        Return attachmentOrder
    End Function

    Public Sub setAttachmentOrder(ByVal order As Integer)
        attachmentOrder = order
    End Sub
End Class

/Email/EmailCOntentsBody.vb

Public Class EmailContentsBody
    Protected underEmailSubjectDirectory As Boolean
    Protected parentalDirectoryId, rank, sequenceNo As Integer
    Protected fileName, position, messages, fileType, result As String
    Protected email As Outlook.MailItem = Nothing
    Protected report As Outlook.ReportItem = Nothing
    Protected mailtype As Integer = 0

    Public Sub New(ByVal letter As Outlook.MailItem, ByVal parent As Integer, ByVal order As Integer, ByVal itemIndex As Integer, ByVal underShelteredDirectory As Boolean, ByVal savedName As String, ByVal area As String, ByVal information As String)
        email = letter
        parentalDirectoryId = parent
        rank = order
        sequenceNo = itemIndex
        underEmailSubjectDirectory = underShelteredDirectory
        fileType = Constants.MSG_FILE_TYPE
        fileName = savedName
        result = New String("")
        position = area
        messages = information
        mailtype = 0
        'InsertHyperLink()
    End Sub

    Public Sub New(ByVal letter As Outlook.ReportItem, ByVal parent As Integer, ByVal order As Integer, ByVal itemIndex As Integer, ByVal underShelteredDirectory As Boolean, ByVal savedName As String, ByVal area As String, ByVal information As String)
        report = letter
        parentalDirectoryId = parent
        rank = order
        sequenceNo = itemIndex
        underEmailSubjectDirectory = underShelteredDirectory
        fileType = Constants.MSG_FILE_TYPE
        fileName = savedName
        result = New String("")
        position = area
        messages = information
        mailtype = 1
    End Sub

    'Public Sub InsertHyperLink()
    '    If Not email Is Nothing Then
    '        'For index As Integer = 1 To email.Attachments.Count
    '        MsgBox(Me.email.HTMLBody.ToString)
    '        email.HTMLBody = Me.email.HTMLBody.Replace("</div>", "<div id=" & Chr(34) & "asta" & Chr(34) & " style=" & Chr(34) & "border: 3px; border-style:solid; color:#00000" & Chr(34) & "><p class=MsoNormal>Your attachement has been uploaded to DMS.</p><p class=MsoNormal></p><p class=MsoNormal>Click <a href=" _
    '                                                   & Chr(34) & "http://hk.yahoo.com" & Chr(34) & ">Link 1<a> to store into your machine. ASTA</p><div></div>")
    '        MsgBox(Me.email.HTMLBody.ToString)
    '        ' Next
    '    End If
    'End Sub

    Public Function getPosition() As String
        getPosition = position
    End Function

    Public Sub setPosition(ByVal place As String)
        position = place
    End Sub

    Public Function getSubject() As String
        If Not email Is Nothing Then
            Return email.Subject
        ElseIf Not report Is Nothing Then
            Return report.Subject
        Else
            Return Nothing
        End If
    End Function

    Public Function getGotDateTime() As Date
        If Not email Is Nothing Then
            Return email.ReceivedTime
        ElseIf Not report Is Nothing Then
            Return report.ReceivedTime
        Else
            Return Nothing
        End If
    End Function

    Public Overridable Function getLogFileName() As String
        Dim underscore, finalSubject As String
        If Not email Is Nothing Then
            underscore = New String("_")
            finalSubject = CommonUtilities.replaceNullOrVacantEmailSubject(email.Subject)
            finalSubject = CommonUtilities.removeIllegalDirectoryFileNameCharacters(finalSubject)
            getLogFileName = finalSubject + underscore + email.ReceivedTime.ToString("yyyyddMMHHmmss") + underscore
        ElseIf Not report Is Nothing Then
            underscore = New String("_")
            finalSubject = CommonUtilities.replaceNullOrVacantEmailSubject(report.Subject)
            finalSubject = CommonUtilities.removeIllegalDirectoryFileNameCharacters(finalSubject)
            getLogFileName = finalSubject + underscore + report.ReceivedTime.ToString("yyyyddMMHHmmss") + underscore
        Else
            Return Nothing
        End If
    End Function

    Public Overridable Function getResultFileNamePrefix() As String
        Dim underscore, finalSubject As String
        If Not email Is Nothing Then
            underscore = New String("_")
            finalSubject = CommonUtilities.replaceNullOrVacantEmailSubject(email.Subject)
            finalSubject = CommonUtilities.removeIllegalDirectoryFileNameCharacters(finalSubject)
            getResultFileNamePrefix = finalSubject + underscore + fileName + underscore + email.ReceivedTime.ToString("ddMMyyyyHHmmss") + underscore
        ElseIf Not report Is Nothing Then
            underscore = New String("_")
            finalSubject = CommonUtilities.replaceNullOrVacantEmailSubject(report.Subject)
            finalSubject = CommonUtilities.removeIllegalDirectoryFileNameCharacters(finalSubject)
            getResultFileNamePrefix = finalSubject + underscore + fileName + underscore + report.ReceivedTime.ToString("ddMMyyyyHHmmss") + underscore
        Else
            Return Nothing
        End If
    End Function

    Public Function isUnderEmailSubjectDirectory() As Boolean
        isUnderEmailSubjectDirectory = underEmailSubjectDirectory
    End Function

    Public Sub setUnderEmailSubjectDirectory(ByVal extraDirectory As Boolean)
        underEmailSubjectDirectory = extraDirectory
    End Sub

    Public Function getFileName() As String
        getFileName = fileName
    End Function

    Public Sub setFileName(ByVal name As String)
        fileName = name
    End Sub

    Public Overridable Function getFileSize() As Double
        If Not email Is Nothing Then
            getFileSize = Math.Round(email.Size / 1024, 2)
        ElseIf Not report Is Nothing Then
            getFileSize = Math.Round(report.Size / 1024, 2)
        Else : Return 0
        End If
    End Function

    Public Function getLastUpdateDateTime() As Date
        If Not email Is Nothing Then
            getLastUpdateDateTime = email.LastModificationTime
        ElseIf Not report Is Nothing Then
            getLastUpdateDateTime = report.LastModificationTime
        Else : Return Now
        End If
    End Function

    Public Function getRank() As Integer
        getRank = rank
    End Function

    Public Sub setRank(ByVal order As Integer)
        rank = order
    End Sub

    Public Function getEmail() As Outlook.MailItem
        Return email
    End Function

    Public Function getReport() As Outlook.ReportItem
        Return report
    End Function

    Public Sub setEmail(ByVal letter As Outlook.MailItem)
        email = letter
    End Sub

    Public Function getParentalDirectoryId() As Integer
        Return parentalDirectoryId
    End Function

    Public Sub setParentalDirectoryId(ByVal parent As Integer)
        parentalDirectoryId = parent
    End Sub

    Public Function getSequenceNo() As Integer
        Return sequenceNo
    End Function

    Public Sub setSequenceNo(ByVal itemIndex As Integer)
        sequenceNo = itemIndex
    End Sub

    Public Function getMessages() As String
        Return messages
    End Function

    Public Sub setMessages(ByVal information As String)
        messages = information
    End Sub

    Public Function getFileType() As String
        Return fileType
    End Function

    Public Function getResult() As String
        Return result
    End Function

    Public Sub setResult(ByVal consequence As String)
        result = consequence
    End Sub

    Public Function getMailtype() As Integer
        getMailtype = mailtype
    End Function

End Class

当我尝试像发送电子邮件一样调试它时,第一次运行很顺利,但是我需要第二次单击两次发送按钮,就像这样。

The videos of double click button 任何人都可以请告诉发生了什么事。

谢谢。

0 个答案:

没有答案