VB.net 2005 使用 Outlook 2003 发送电子邮件

发布于 2024-09-12 01:56:30 字数 871 浏览 5 评论 0原文

目前,我们使用以下代码在 Outlook 中创建电子邮件,以便用户可以在 Outlook 中键入他们想要的内容,然后在发送电子邮件时,系统会提示他们是否要保存电子邮件。

            Dim objOutlook As Object
            Dim objMessage As Object
            Dim objInspector As Object

            If strEMail <> "" Then
                objOutlook = CreateObject("Outlook.Application")
                objMessage = objOutlook.CreateItem(0)
                objMessage.To = strEMail

                objInspector = objMessage.GetInspector
                objInspector.Display()

                While Not objInspector.CurrentItem Is Nothing
                End While

                frmSaveSentEmail.BringToFront()
                frmSaveSentEmail.ShowDialog()

只要不使用 Word 作为电子邮件编辑器,该代码就可以在 Outlook 2003 上正常运行。但是,将 Word 设置为电子邮件编辑器后,测试电子邮件对象是否已关闭的 while 循环永远不会结束。

有没有办法以不同的方式处理这个问题,以便即使使用 Word 作为编辑器也能正常工作?

We currently use the following code to create an email in Outlook so that the user can type what they want in Outlook, then when the email is sent, the system prompts them to see if they would like to save the email.

            Dim objOutlook As Object
            Dim objMessage As Object
            Dim objInspector As Object

            If strEMail <> "" Then
                objOutlook = CreateObject("Outlook.Application")
                objMessage = objOutlook.CreateItem(0)
                objMessage.To = strEMail

                objInspector = objMessage.GetInspector
                objInspector.Display()

                While Not objInspector.CurrentItem Is Nothing
                End While

                frmSaveSentEmail.BringToFront()
                frmSaveSentEmail.ShowDialog()

The code works fine on Outlook 2003 as long as they are not using Word as their email editor. However, with Word set up as the email editor, the while loop that tests to see if the email object is closed never ends.

Is there a way to handle this differently so that it will work even with Word as the editor?

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

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

发布评论

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

评论(2

瑶笙 2024-09-19 01:56:30

我对通过 VB.NET 编程 Outlook 没有太多经验,但这个循环看起来确实很可疑。也许您应该尝试利用检查员的 关闭事件,而不是重复检查其CurrentItem属性。如果我没有记错的话,您应该能够在事件处理程序中呈现您的对话框。

I am not terribly experienced with programming Outlook via VB.NET, but that loop certainly looks suspicious. Perhaps you should try taking advantage of the inspector's Close event instead of repeatedly checking its CurrentItem property. If I am not mistaken, you should be able to present your dialog within the event handler.

与之呼应 2024-09-19 01:56:30

最终将循环更改为:

  While Not objOutlook.ActiveInspector Is Nothing
  End While

这解决了问题。

Ended up changing the loop to:

  While Not objOutlook.ActiveInspector Is Nothing
  End While

This resolved the issue.

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