VB.net 2005 使用 Outlook 2003 发送电子邮件
目前,我们使用以下代码在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对通过 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 itsCurrentItem
property. If I am not mistaken, you should be able to present your dialog within the event handler.最终将循环更改为:
这解决了问题。
Ended up changing the loop to:
This resolved the issue.