PDA

View Full Version : Send Email Via Gmail



Sjheskett
04-11-2013, 05:52 AM
Hello,


I am after some help I have been trying to get MS Access to generate an email. The company I work at use GMAIL as the default client but I just can't seem to get Access to create the email.

Is there anyone who can help?

Steve

JuanEsmith
05-16-2013, 07:44 AM
You need a reference to the Microsoft CDO For Windows 2000 library for the following method. This was adapted from a module in my code base that sends emails via an internal SMTP server. I have roughly updated it for gmail but can't guarantee it will work off the bat.

You will need to change | to / because I can't post links.

Public Sub SendEmail(Message As String, Subject As String, Recipient As String, Optional attachments)

Const strSch = "http:||schemas.microsoft.com|cdo|configuration|"


Dim cdoCDOConfig As New CDO.Configuration

With cdoCDOConfig.Fields

.Item(strSch & "sendusing") = cdoSendUsingPort
.Item(strSch & "smtpauthenticate") = 1
.Item(strSch & "smtpusessl") = True
.Item(strSch & "smtpserver") = "smtp.gmail.com"
.Item(strSch & "sendusername") = "senderName@gmail.com"
.Item(strSch & "sendpassword") = "senderPassword"
.Item(strSch & "smtpserverport") = 465
.Item(strSch & "connectiontimeout") = 100
.Update
End With

Dim cdoMessage As New CDO.Message
With objCDOMessage
Set .Configuration = objCDOConfig
.From = "senderName@gmail.com"
.To = Recipient
.Subject = Subject
.TextBody = "This is a test for CDO.message"
.HTMLBody = Greeting & Message & Signature
AddAttachments objCDOMessage, attachments
.Send
End With


Set cdoMessage = Nothing
Set CDOConfig = Nothing
End Sub