In a module, I am using the following:
Code:
Public Sub SendGmail()
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mytestuser@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myHighlySecurePassword"
.Update
End With
' build email parts
With cdomsg
.To = "mytestuser@gmail.com"
.From = "mytestuser@gmail.com"
.Subject = "Message From Access"
.TextBody = "This message sent from Microsoft Access 2007 via Gmail."
.AddAttachment "c:\myexcelfile.xlsx"
.Send
End With
Set cdomsg = Nothing
MsgBox ("Sent the messsage")
End Sub
and when the email is triggered, it does not use port 587 as the code dictates. Instead port 25 is opened. I am using the free TCP port monitoring utility "currports" and can visually see port 25 opened by msaccess.exe.
How can I get 587 to work?