MS Access VBA:通过Outlook发送电子邮件
问题描述:
如何使用MS Access VBA通过帐户发送电子邮件?我知道这个问题含糊不清,但是很难在网上找到没有以某种方式过时的相关信息.
How can I send an email through an account using MS Access VBA? I know this question is vague but it's so hard to find the relevant information online that isn't outdated in some way.
我并不是要对那些要回答的人不礼貌,但是我正在使用MS Access .我无法在Outlook VBA中编写实际的代码.
I don't mean to be rude to those who are answering, but I am using MS Access. I cannot write the actual code in Outlook VBA.
答
在Visual Basic编辑器中添加对Outlook对象模型的引用.然后,您可以使用下面的代码使用Outlook发送电子邮件.
Add a reference to the Outlook object model in the Visual Basic editor. Then you can use the code below to send an email using outlook.
Sub sendOutlookEmail()
Dim oApp As Outlook.Application
Dim oMail As MailItem
Set oApp = CreateObject("Outlook.application")
Set oMail = oApp.CreateItem(olMailItem)
oMail.Body = "Body of the email"
oMail.Subject = "Test Subject"
oMail.To = "Someone@somewhere.com"
oMail.Send
Set oMail = Nothing
Set oApp = Nothing
End Sub