在没有 MAPI 的情况下使用 Access 和 VBA 发送电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/769763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
email using Access and VBA without MAPI
提问by Knox
I would like to send email from Microsoft Access unattended using VBA. I understand that the built-in method “SendObject” uses MAPI meaning security prompts and something like Outlook configured. Since I want to use the Task Scheduler to kick off different reports, I'm leaning away from MAPI and would prefer some other solution. Not an application for shipping but just in-house. Ideas?
我想使用 VBA 从无人值守的 Microsoft Access 发送电子邮件。我知道内置方法“SendObject”使用 MAPI 表示安全提示和类似 Outlook 配置的东西。因为我想使用任务计划程序来启动不同的报告,所以我倾向于远离 MAPI 而更喜欢一些其他的解决方案。不是运输申请,而是内部申请。想法?
采纳答案by JeffO
You'll need an SMTP server that will allow you to send email. Then you need to use the CDO message object.
您将需要一个 SMTP 服务器来允许您发送电子邮件。然后你需要使用 CDO 消息对象。
回答by Knox
Here's the test code that worked for me with CDO and gmail.
这是对我来说适用于 CDO 和 gmail 的测试代码。
Sub mtest()
Dim cdoConfig
Dim msgOne
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "gmailname"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpw"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Update
End With
Set msgOne = CreateObject("CDO.Message")
Set msgOne.Configuration = cdoConfig
msgOne.To = "[email protected]"
msgOne.From = "[email protected]"
msgOne.Subject = "Test email"
msgOne.TextBody = "It works just fine"
msgOne.send
End Sub
回答by Ron
I do it this way, note, you must have Outlook installed for it to work.
我是这样做的,请注意,您必须安装 Outlook 才能工作。
Sub btnSendEmail_Click()
Dim OutApp As Object
Dim OutMail As Object
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
strBody = "<html><head></head><body>"
strBody = strBody & "Your message goes here"
strBody = strBody & "</body></html>"
Set OutMail = OutApp.CreateItem(0)
OutMail.To = "[email protected]"
OutMail.BCC = "[email protected]"
OutMail.Subject = "Test message"
OutMail.HTMLBody = strBody
OutMail.Send 'Send | Display
Set OutMail = Nothing
End Sub
回答by Oorang
Outlook Redemption is free and very widely used: http://www.dimastr.com/redemption/
Outlook Redemption 是免费的并且使用非常广泛:http: //www.dimastr.com/redemption/
It is very very close to the original outlook object model, so the learning curve is cake:)
它非常非常接近原始的outlook对象模型,所以学习曲线是蛋糕:)
回答by David-W-Fenton
You might find Tony Toews's Access EMail FAQhandy.
您可能会发现 Tony Toews 的访问电子邮件常见问题很方便。

