A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Trying to Create Email Function



 
 
Thread Tools Display Modes
  #1  
Old April 19th, 2010, 07:46 PM posted to microsoft.public.access
Sharkbyte
external usenet poster
 
Posts: 110
Default Trying to Create Email Function

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")
= "
.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



  #2  
Old April 19th, 2010, 09:06 PM posted to microsoft.public.access
Daniel Pineault
external usenet poster
 
Posts: 658
Default Trying to Create Email Function

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



  #3  
Old April 19th, 2010, 09:33 PM posted to microsoft.public.access
Sharkbyte
external usenet poster
 
Posts: 110
Default Trying to Create Email Function

Daniel:

Thanks for the link. I will look at it.

In regards to your question, yes, it returns the following error:

'The transport failed to connect to the server. Error number: -2147220973'

Sharkbyte



"Daniel Pineault" wrote:

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



  #4  
Old April 19th, 2010, 09:45 PM posted to microsoft.public.access
Sharkbyte
external usenet poster
 
Posts: 110
Default Trying to Create Email Function

Daniel:

Using the code from your link, I get the same Transport error. It would
seem my GMail connection lines are incorrect, but all the information I can
find says that I'm pointing to the right place...

I will keep trying.

Sharkbyte


"Daniel Pineault" wrote:

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



  #5  
Old April 20th, 2010, 02:43 AM posted to microsoft.public.access
Daniel Pineault
external usenet poster
 
Posts: 658
Default Trying to Create Email Function

It may be coincidence, but the three examples I have found only for using CDO
with gmail use port 465??? Might be worth a try.
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

Daniel:

Using the code from your link, I get the same Transport error. It would
seem my GMail connection lines are incorrect, but all the information I can
find says that I'm pointing to the right place...

I will keep trying.

Sharkbyte


"Daniel Pineault" wrote:

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



  #6  
Old April 20th, 2010, 02:45 AM posted to microsoft.public.access
Daniel Pineault
external usenet poster
 
Posts: 658
Default Trying to Create Email Function

Here is a CDO example explicitly for gmail hopefully it can help.

http://www.a1vbcode.com/snippet-3691.asp
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

Daniel:

Using the code from your link, I get the same Transport error. It would
seem my GMail connection lines are incorrect, but all the information I can
find says that I'm pointing to the right place...

I will keep trying.

Sharkbyte


"Daniel Pineault" wrote:

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



  #7  
Old April 20th, 2010, 02:47 AM posted to microsoft.public.access
Daniel Pineault
external usenet poster
 
Posts: 658
Default Trying to Create Email Function

2 more samples to check out

http://www.ozgrid.com/forum/showthread.php?t=84628
http://codingsense.wordpress.com/200...-using-vb-6-0/
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

Daniel:

Using the code from your link, I get the same Transport error. It would
seem my GMail connection lines are incorrect, but all the information I can
find says that I'm pointing to the right place...

I will keep trying.

Sharkbyte


"Daniel Pineault" wrote:

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



  #8  
Old April 20th, 2010, 03:46 PM posted to microsoft.public.access
Sharkbyte
external usenet poster
 
Posts: 110
Default Trying to Create Email Function

Daniel:

Thank you for sticking with this one. This sample code worked.

It appears I wasn't calling Authentication and SSL correctly, so the server
wouldn't accept my request.

Thanks again.

Sharkbyte


"Daniel Pineault" wrote:

Here is a CDO example explicitly for gmail hopefully it can help.

http://www.a1vbcode.com/snippet-3691.asp
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

Daniel:

Using the code from your link, I get the same Transport error. It would
seem my GMail connection lines are incorrect, but all the information I can
find says that I'm pointing to the right place...

I will keep trying.

Sharkbyte


"Daniel Pineault" wrote:

Failing? Do you get an error?

You might want to take a look at the following example for inspiration

http://www.worksrite.com/CDOMail.htm
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Sharkbyte" wrote:

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")
= "
.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



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.