通过 Outlook 从 Access VBA 发送自动电子邮件 [英] Sending Automated Email from Access VBA through Outlook
问题描述
好的,所以我一直在一个简单的代码片段上将创可贴放在创可贴之上,以获取要发送的电子邮件.我一直在尝试做的是通过 Outlook 发送一封电子邮件.我的第一个问题是 runtime objectdefine 287
在以下行:
Ok, so I've been putting band aids on top of band aids on a simple snippet of code to get an email to send. What I've been trying to do is get an email to send through outlook. My first issue was runtime object define 287
at the following line:
Set appOutlookRec = appOutlookMsg.Recipients.Add
为了反驳我添加的内容:
so to counter that I added:
Set objNS = appOutlook.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
这就停止了.现在电子邮件将形成,我可以使用 .display
查看我的电子邮件,但是当我尝试使用 .send
时,Outlook 实例在电子邮件实际发送之前关闭.
And that stopped that. Now the email will form and I can use .display
to see my email, but when I try and use .send
the instance of Outlook closes before the email is actually sent.
为了反驳我强制打开 Outlook,但我想检查一个实例是否已经打开.要打开我使用的收件箱:
To counter that I force outlook to open, but I would like to check if an instance is already open. To open the inbox I use:
Set appOutlook = CreateObject("Outlook.Application")
Set objNS = appOutlook.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
olFolder.Display
我是否使自动化过程过于复杂?或者我是否在正确的道路上,有人可以帮助检查 Outlook 的实例是否在资源管理器窗口中打开?
Am I over complicating the automation process? Or am I on the right path and someone can help checking if an instance of Outlook is open in the explorer window?
谢谢
更新
Const olMailItem = 0
Const olTo = 1
Const olCC = 2
Const olFolderInbox = 6
Dim appOutlook As Object
Dim appOutlookMsg As Object
Dim appOutlookRec As Object
Dim objNS As Object
Dim olFolder As Object
Set appOutlook = CreateObject("Outlook.Application")
Set objNS = appOutlook.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
olFolder.Display
'Create a new empty email message
Set appOutlookMsg = appOutlook.CreateItem(olMailItem)
With appOutlookMsg
Set appOutlookRec = appOutlookMsg.Recipients.Add("....@gmail.com")
appOutlookRec.Type = olTo
.Subject = "Testing Closed Tickets"
.Body = "This is just a test."
'.Display
.Send
End With
Set appOutlookMsg = Nothing
Set appOutlook = Nothing
Set appOutlookRec = Nothing
推荐答案
我以前遇到过类似的事情,我认为通常您可以通过在发送前保存电子邮件来避免错误:
I've encountered something similar before and I think usually you can avoid the error by saving the email prior to sending:
appOutlookMsg.Save
appOutlookMsg.Send
这篇关于通过 Outlook 从 Access VBA 发送自动电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!