2009-07-16 76 views
3

我需要從MS Access數據庫發送一系列電子郵件通知。從MS Access發送電子郵件沒有第三方DLL允許

  • 任何第三方DLL的像贖回
  • 無法跌倒Outlook安全警告
  • 電子郵件將有一個PDF附件

我知道要做到這一點我需要使用MAPI,但我似乎無法找到一種方法來與VBA做到這一點。

任何幫助,將不勝感激

感謝,

斯科特

回答

2

如果您可以忍受要求CDO出現在T上他機器,你不介意用戶提供的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 = "[email protected]" 
    .CC = "" 
    .BCC = "" 
    .From = """Ron"" <[email protected]>" 
    .Subject = "Important message" 
    .TextBody = strbody 
    .Send 
End With 

End Sub 

添加附件將使用.AddAttachment「C:\文件\ filename.pdf」來完成上IMSG。

+0

我正在玩這個想法開始,這是我決定去的方式 - 感謝 – Scott 2009-07-17 12:45:01

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 = "[email protected]" 
    .Subject = "Graph Info " & Format(Now(), "dd mmm yyyy hh:mm") 
    .Attachments.Add strFileName 
    .ReadReceiptRequested = False 
    .Send 
End With 
Kill strFileName 

還檢查了託尼·託斯的Microsoft Access Email FAQ

+0

這是一個很好的資源,但不包含實際的問題答案。雖然我必須說,我不認爲滿足所有限制的答案是存在的。 – 2009-07-16 18:23:30