【发布时间】:2009-07-16 14:06:58
【问题描述】:
我需要从 MS Access 数据库发送一系列电子邮件通知。
- 没有像 Redemption 这样的第三方 dll
- 无法触发 Outlook 安全警告
- 电子邮件将包含 pdf 附件
我知道要做到这一点,我需要使用 MAPI,但我似乎找不到用 VBA 做到这一点的方法。
任何帮助将不胜感激
谢谢,
斯科特
【问题讨论】:
我需要从 MS Access 数据库发送一系列电子邮件通知。
我知道要做到这一点,我需要使用 MAPI,但我似乎找不到用 VBA 做到这一点的方法。
任何帮助将不胜感激
谢谢,
斯科特
【问题讨论】:
如果您可以接受要求机器上存在 CDO,并且您不介意用户提供的 SMTP 服务器,则可以使用它。只是谷歌一些示例代码,但为了您的方便,我将在下面粘贴一些来自www.rondebruin.nl:
Sub CDO_Mail_Small_Text()
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
' Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
' iConf.Load -1 ' CDO Source Defaults
' Set Flds = iConf.Fields
' With Flds
' .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
' = "Fill in your SMTP server here"
' .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
' .Update
' End With
strbody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2" & vbNewLine & _
"This is line 3" & vbNewLine & _
"This is line 4"
With iMsg
Set .Configuration = iConf
.To = "ron@debruin.nl"
.CC = ""
.BCC = ""
.From = """Ron"" <ron@something.nl>"
.Subject = "Important message"
.TextBody = strbody
.Send
End With
End Sub
在 iMsg 上使用 .AddAttachment "C:\files\filename.pdf" 添加附件。
【讨论】:
如果用户安装了 Outlook:
Dim strErrMsg As String 'For Error Handling
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim oleGrf As Object
Dim strFileName As String
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olMail = olApp.CreateItem(olMailItem)
Set oleGrf = Me.OLEchart.Object
strFileName = "c:\temp\Graph.jpg"
oleGrf.Export FileName:=strFileName
With olMail
.To = "someone@somewhere.com"
.Subject = "Graph Info " & Format(Now(), "dd mmm yyyy hh:mm")
.Attachments.Add strFileName
.ReadReceiptRequested = False
.Send
End With
Kill strFileName
还可以查看 Tony Toews 的Microsoft Access Email FAQ
【讨论】:
查看页面Microsoft Access Email FAQ - Directly via the Winsock这些我自己没试过,但你应该可以修改VB6代码直接发送电子邮件。
【讨论】: