S
Sharkbyte
I have not worked with sending email from Access, before, but now I am
attempting to create a function that will generate an email in response to
certain user actions.
I have cobbled together some code, and I believe it is close to functional.
However, I am failing when trying to connect to Google's GMail server.
I'm hoping someone can point me in the right direction, or to an How To
article...
Here is my code:
Public Function SendEMail_CDO1(strFrom, strTo, strSubject, strBody,
strSmtpServer, strSendUserName, strPassword, Optional strCC) As Boolean
On Error GoTo ErrorHandling
Dim mail
Dim config
Dim fields
Dim i As Integer
Set mail = CreateObject("CDO.Message")
Set config = CreateObject("CDO.Configuration")
Set fields = config.fields
With fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"smtp.gmail.com"
..Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =
True
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
= "(e-mail address removed)"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
= "xxxx"
..Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 15
.Update
End With
Set mail.Configuration = config
With mail
.From = strFrom
.To = strTo
.Subject = strSubject
.TextBody = strBody
If blnAttachedFile = True Then
.AddAttachment = strAttachedFile
Else
End If
.Send
End With
Set mail = Nothing
Set fields = Nothing
Set config = Nothing
SendEMail_CDO1 = True
Exit Function
ErrorHandling:
MsgBox Err.Description & " Error Number: " & Err.Number
Debug.Print Err.Description & " " & Err.Number
SendEMail_CDO1 = False
Set mail = Nothing
Set fields = Nothing
Set config = Nothing
End Function
attempting to create a function that will generate an email in response to
certain user actions.
I have cobbled together some code, and I believe it is close to functional.
However, I am failing when trying to connect to Google's GMail server.
I'm hoping someone can point me in the right direction, or to an How To
article...
Here is my code:
Public Function SendEMail_CDO1(strFrom, strTo, strSubject, strBody,
strSmtpServer, strSendUserName, strPassword, Optional strCC) As Boolean
On Error GoTo ErrorHandling
Dim mail
Dim config
Dim fields
Dim i As Integer
Set mail = CreateObject("CDO.Message")
Set config = CreateObject("CDO.Configuration")
Set fields = config.fields
With fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"smtp.gmail.com"
..Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") =
True
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")
= "(e-mail address removed)"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")
= "xxxx"
..Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 15
.Update
End With
Set mail.Configuration = config
With mail
.From = strFrom
.To = strTo
.Subject = strSubject
.TextBody = strBody
If blnAttachedFile = True Then
.AddAttachment = strAttachedFile
Else
End If
.Send
End With
Set mail = Nothing
Set fields = Nothing
Set config = Nothing
SendEMail_CDO1 = True
Exit Function
ErrorHandling:
MsgBox Err.Description & " Error Number: " & Err.Number
Debug.Print Err.Description & " " & Err.Number
SendEMail_CDO1 = False
Set mail = Nothing
Set fields = Nothing
Set config = Nothing
End Function