我想使用 VBA 在无人值守的情况下从 Microsoft Access 发送电子邮件。我知道内置方法“SendObject”使用 MAPI 表示安全提示和类似 Outlook 配置的东西。因为我想使用任务计划程序来启动不同的报告,所以我倾向于远离 MAPI,并且更喜欢其他一些解决方案。不是运输申请,而是内部申请。想法?
问问题
22155 次
5 回答
5
这是适用于 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 = "target@target.com"
msgOne.From = "I@dontThinkThisIsUsed.com"
msgOne.Subject = "Test email"
msgOne.TextBody = "It works just fine"
msgOne.send
End Sub
于 2009-04-21T21:03:35.630 回答
1
您需要一个允许您发送电子邮件的 SMTP 服务器。然后您需要使用 CDO 消息对象。
于 2009-04-20T19:36:19.967 回答
1
您可能会发现 Tony Toews 的Access EMail FAQ很方便。
于 2009-04-20T20:23:59.993 回答
1
我是这样做的,注意,你必须安装 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 = "name@example.com"
OutMail.BCC = "bcc@example.com"
OutMail.Subject = "Test message"
OutMail.HTMLBody = strBody
OutMail.Send 'Send | Display
Set OutMail = Nothing
End Sub
于 2009-04-21T21:13:25.857 回答
1
Outlook Redemption 是免费的并且使用非常广泛:http ://www.dimastr.com/redemption/
它非常接近原始的 Outlook 对象模型,因此学习曲线很简单:)
于 2009-06-11T06:25:24.550 回答