使用 Access 和 VBA 发送电子邮件,无需 MAPI

发布于 2024-07-17 05:18:49 字数 178 浏览 12 评论 0原文

我想使用 VBA 在无人值守的情况下从 Microsoft Access 发送电子邮件。 据我了解,内置方法“SendObject”使用 MAPI,意味着安全提示和 Outlook 配置之类的内容。 由于我想使用任务计划程序来启动不同的报告,因此我倾向于放弃 MAPI,而更喜欢其他解决方案。 不是运输申请,只是内部申请。 有想法吗?

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?

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

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

发布评论

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

评论(5

街道布景 2024-07-24 05:18:49

这是适用于我的 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

Here's the test code that worked for me with CDO and 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
中性美 2024-07-24 05:18:49

您需要一个 SMTP 服务器来发送电子邮件。 那么你需要使用CDO消息对象。

You'll need an SMTP server that will allow you to send email. Then you need to use the CDO message object.

断爱 2024-07-24 05:18:49

您可能会发现 Tony Toews 的访问电子邮件常见问题解答很方便。

You might find Tony Toews's Access EMail FAQ handy.

骷髅 2024-07-24 05:18:49

我是这样做的,注意,你必须安装 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

I do it this way, note, you must have Outlook installed for it to work.


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
风追烟花雨 2024-07-24 05:18:49

Outlook Redemption 是免费的并且使用非常广泛:http://www.dimastr.com/redemption/

它非常非常接近原始的 Outlook 对象模型,因此学习曲线很简单:)

Outlook Redemption is free and very widely used: http://www.dimastr.com/redemption/

It is very very close to the original outlook object model, so the learning curve is cake:)

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