从MS Access发送电子邮件不允许第三方dll

时间:2009-07-16 14:06:58

标签: ms-access vba outlook

我需要从MS Access数据库发送一系列电子邮件通知。

  • 没有第三方dll像Redemption
  • 无法触发Outlook安全警告
  • 电子邮件将附有pdf附件

我知道这样做我需要使用MAPI,但我似乎无法找到一种方法来使用VBA。

任何帮助将不胜感激

谢谢,

斯科特

3 个答案:

答案 0 :(得分:2)

如果您可以要求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”来添加附件。

答案 1 :(得分:0)

如果用户安装了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

答案 2 :(得分:0)

请参阅页面Microsoft Access Email FAQ - Directly via the Winsock我自己没有尝试过,但您应该能够调整VB6代码直接发送电子邮件。