I always used CDO to email back in Access 97/2000/2003. Here's the code I used to use with the Microsoft CDO For Exchange 2000 library:
Sub testCDOMail()
Dim success As Boolean
Dim strSendTo As String
strSendTo = "alias1@domain.com; alias2@domain.com"
success = SendCDOMail(strSendTo, "Test CDO Mail", "just testing", "", False)
MsgBox "Success = " & success
End Sub
Dim success As Boolean
Dim strSendTo As String
strSendTo = "alias1@domain.com; alias2@domain.com"
success = SendCDOMail(strSendTo, "Test CDO Mail", "just testing", "", False)
MsgBox "Success = " & success
End Sub
Public Function SendCDOMail(strTo As String, strSubject As String, strBody As String, strAttach As String, blnHTML As Boolean) As Boolean
On Error GoTo Failure
Dim objMessage As CDO.Message
Dim objConfig As CDO.Configuration
Dim objFields As Variant
Const cboSendUsingPort As Integer = 2
Set objConfig = New CDO.Configuration
Set objMessage = New CDO.Message
Set objFields = objConfig.Fields
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.0.10" '<-- valid SMTP server IP or hostname
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 5
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "valid_username"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "valid_password" '<--this is in plain text so maybe set up special limited account for this purpose
.Update
End With
With objMessage
Set .Configuration = objConfig
.To = strTo
.From = "alias3@domain.com"
.subject = strSubject
If blnHTML = True Then
.HTMLBody = strBody
Else
.TextBody = strBody
End If
If strAttach <> "" Then .AddAttachment (strAttach)
.Send
End With
Set objMessage = Nothing
Set objFields = Nothing
Set objConfig = Nothing
SendCDOMail = True
EXITROUTINE:
Exit Function
Failure:
SendCDOMail = False
MsgBox Err & " " & Err.Description
Resume EXITROUTINE
End Function
On Error GoTo Failure
Dim objMessage As CDO.Message
Dim objConfig As CDO.Configuration
Dim objFields As Variant
Const cboSendUsingPort As Integer = 2
Set objConfig = New CDO.Configuration
Set objMessage = New CDO.Message
Set objFields = objConfig.Fields
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.0.10" '<-- valid SMTP server IP or hostname
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 5
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "valid_username"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "valid_password" '<--this is in plain text so maybe set up special limited account for this purpose
.Update
End With
With objMessage
Set .Configuration = objConfig
.To = strTo
.From = "alias3@domain.com"
.subject = strSubject
If blnHTML = True Then
.HTMLBody = strBody
Else
.TextBody = strBody
End If
If strAttach <> "" Then .AddAttachment (strAttach)
.Send
End With
Set objMessage = Nothing
Set objFields = Nothing
Set objConfig = Nothing
SendCDOMail = True
EXITROUTINE:
Exit Function
Failure:
SendCDOMail = False
MsgBox Err & " " & Err.Description
Resume EXITROUTINE
End Function
But if you are on Outlook 2010, it looks like that probably doesn't work anymore:
Maybe you can figure out how to use the Outlook 2010 object model:
Or there's always Outlook Redemption:
Hope that helps,
Toby
-----Original Message-----
From: AccessDevelopers@yahoogroups.com [mailto:AccessDevelopers@yahoogroups.com] On Behalf Of Jay
Sent: Saturday, May 05, 2012 2:51 PM
To: AccessDevelopers@yahoogroups.com
Subject: [AccessDevelopers] Emailing From AccessI am using MS Access 2007. I have a database with email addresses in clients records. I also have Outlook 2010. When I try and create an email it says I need Outlook 2007.
Is there another way to send emails?
Thanks
Jay Beckham
Cruises On The Sea.
__._,_.___
Please zip all files prior to uploading to Files section.
.
__,_._,___
Tidak ada komentar:
Posting Komentar