office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Access或Excel VBA使用CDO批量發送郵件

2019-07-15 16:06:00
zstmtony
原創
1001



ACCESS及VBA可以通過微軟的CDO來發送郵件, (不需要安裝其他控件和引用DLL庫文件)這樣使用非常方便,比調用Outlook的MAPI更加方便
 

Dim objEmail As Object
Dim strName As String

 

Private Sub Form_Load()
    strName = "http://schemas.microsoft.com/cdo/configuration/"
    Set objEmail = CreateObject("CDO.Message")
End Sub

Private Sub Command1_Click()
    Me.Caption = "正在發送..."
    Command1.Enabled = False
    objEmail.From = "[email protected]"
    objEmail.To = "[email protected]"
    objEmail.Subject = "郵件發送測試(Access交流網)"
    objEmail.Textbody = "郵件發送測試內容(Office中國交流網)"
    objEmail.Configuration.Fields.Item(strName & "sendusing") = 2
    objEmail.Configuration.Fields.Item(strName & "smtpserver") = "smtp.21cn.com"
    objEmail.Configuration.Fields.Item(strName & "smtpserverport") = 25
    objEmail.Configuration.Fields.Item(strName & "smtpauthenticate") = 1
    objEmail.Configuration.Fields.Item(strName & "sendusername") = "[email protected]"
    objEmail.Configuration.Fields.Item(strName & "sendpassword") = "XXXXXXXXXX"
    objEmail.Configuration.Fields.Update
    objEmail.Send
    Command1.Enabled = True
    Me.Caption = "Send OK!"
    MsgBox "郵件發送成功,謝謝,歡迎您使用Access交流網的代碼"
    End
End Sub
分享
北京十一选五基本走势