Outlook发送邮件时的调用方法?

发布于 2024-10-11 21:24:30 字数 373 浏览 6 评论 0 原文

有一个名为 MailItemClass 的 VBA 类,它具有 在 Outlook 中发送电子邮件时发生的事件。我找不到 VB.NET 的这个。我浏览了文档但我在 MAPI 中找不到它。

(我可以从VB.NET调用VBA吗?)

There's a VBA class called MailItemClass that has an event for when an e-mail has been sent in Outlook. I can't find this for VB.NET. I've looked through the documentation but I just can't find it in the MAPI.

(Can I call VBA from VB.NET?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初懵 2024-10-18 21:24:30

您正在制作 Outlook 插件吗?有一个名为 Application.ItemSend 的事件在发送项目之前引发。我刚刚启动 VS2010,创建了一个 Outlook 2007 加载项类型的新项目,其中仅包含以下代码,当我单击“从 Outlook 发送”时,我的 Application_ItemSend 按预期触发。

Public Class ThisAddIn

    Private Sub ThisAddIn_Startup() Handles Me.Startup

    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
        System.Windows.Forms.MessageBox.Show("Hi")
    End Sub
End Class

编辑

如果您正在制作一个 WinForms 应用程序,您使用相同的方法,但您“看到”它有点不同。可能有点令人困惑的是,该事件是在应用程序级别引发的,而不是从邮件项目本身引发的。

Public Class Form1
    ''//Holds a reference to our mail application
    Private WithEvents OA As Microsoft.Office.Interop.Outlook.Application

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''//Either launches Outlook or snaps to the current running one
        OA = New Microsoft.Office.Interop.Outlook.Application()
    End Sub

    Private Sub OA_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles OA.ItemSend
        MessageBox.Show("Hello")
    End Sub
End Class

Are you making an Outlook Add-in? There's an event called Application.ItemSend that is raised before an item is sent. I just launched VS2010, created a new project of type Outlook 2007 Add-in that contains just the below code and my Application_ItemSend fired as expected when I clicked Send from Outlook.

Public Class ThisAddIn

    Private Sub ThisAddIn_Startup() Handles Me.Startup

    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend
        System.Windows.Forms.MessageBox.Show("Hi")
    End Sub
End Class

EDIT

If you're making a WinForms app that you use the same method but you "see" it a little differently. What can be a little confusing is that the event is raised at the application level and not from the mail item itself.

Public Class Form1
    ''//Holds a reference to our mail application
    Private WithEvents OA As Microsoft.Office.Interop.Outlook.Application

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''//Either launches Outlook or snaps to the current running one
        OA = New Microsoft.Office.Interop.Outlook.Application()
    End Sub

    Private Sub OA_ItemSend(ByVal Item As Object, ByRef Cancel As Boolean) Handles OA.ItemSend
        MessageBox.Show("Hello")
    End Sub
End Class
暖阳 2024-10-18 21:24:30

VBA 和VB.NET 都使用“Outlook 对象模型”。奇怪的是发送事件被省略了。但是,您仍然有这个 事件

我不太喜欢 VB,但由于 MAPI 是面向 C++ 的,因此从 VB.net 使用它听起来不太精简,但 MailItem 将大致对应于 LPMESSAGE。各种 Outlook 插件框架都有相当好的通知系统。如果您需要单独使用 MAPI,请检查 MAPI 事件,...但这并不容易。

Both VBA and VB.NET use the "Outlook Object Model". It is odd that the send event is omitted. However, you still have this event.

I'm not much of VB guy, but as MAPI is oriented to C++, using it from VB.net doesn't sound very streamlined, but the MailItem will roughly correspond to LPMESSAGE. The various outlook addin frameworks have pretty good notification systems in place. If you need go with MAPI alone, check MAPI events, ...but it's not easy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文