0

这个问题很可能之前已经被问过(很多次),但我找不到解决方案。

我有一个可以发送电子邮件的程序。代码看起来像这样:

Dim oApp As Interop.Outlook.Application = Nothing
While oApp Is Nothing
    Try
        oApp = New Interop.Outlook.Application
    Catch ex As Exception
        oApp = Nothing
        Dim result As Integer = MessageBox.Show("Outlook is already running, close Outlook and click OK to continue sending this email or click Cancel to skip sending this email.", "Outlook", MessageBoxButtons.OKCancel)
        If result = DialogResult.Cancel Then
            Exit Sub
        End If
    End Try
End While

到目前为止,一切都很好。用户被迫关闭 Outlook 以使用 Outlook 应用程序。完成后,我这样做:

Dim eMail As Interop.Outlook._MailItem
eMail = oApp.CreateItem(Interop.Outlook.OlItemType.olMailItem)

'To who?
eMail.To = "person@domain.com"

'Sbuject
eMail.Subject = "Foo"

'Message
Dim message As String = "Bar"
eMail.HTMLBody = message

'Send
eMail.Send()

像魅力一样工作,但是完成后,我在托盘中有这个小图标,告诉我 Outlook 正在运行,如果我尝试打开我的 Outlook 客户端,我会收到一条消息,指出 Outlook 已经在运行。我必须单击托盘中的图标关闭才能使用客户端。发送邮件时如何从我的代码中关闭此应用程序?

我试过这个没有成功:

oApp.Quit()
oApp.Application.Quit()
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(oApp)
oApp = Nothing

任何帮助表示赞赏。

4

0 回答 0