我想使用VBA从Microsoft Access发送电子邮件。我了解内置方法“ sendobject”使用MAPI表示安全提示,并采用了类似的Outlook配置。由于我想使用任务调度程序来启动不同的报告,因此我偏离了MAPI,并且更喜欢其他解决方案。不是运输的申请,而只是内部。想法?

有帮助吗?

解决方案

您将需要一台SMTP服务器,该服务器将允许您发送电子邮件。然后,您需要使用CDO消息对象。

其他提示

这是与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

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

我这样做,请注意,您必须安装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

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

它非常接近原始的Outlook对象模型,因此学习曲线是蛋糕:)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top