Gmail email sending through VBA run time errors

Bering

Board Regular
Joined
Aug 22, 2018
Messages
63
Hello,

I am working on a macro that identifies the username, asks for the account password and sends out an email from Gmail.

I tested it using my personal gmail account and worked like a charm with the default settings smtp.gmail.com and port 25.

However, I couldn't manage to make it work for the actual company account.

Since my company uses Gmail with a custom domain, (my email address is, say, John.Smith@CompanyX.com), I figured I had to change smtp.gmail.com to smtp.CompanyX.com

I have also tried using different ports (465,587) but nothing has worked so far and I keep getting several run time errors (80040213, 80040217..)...

I could really use some help, especially to identify the correct smtp and port for this domain.

Any ideas?

Thank you.



Set Mail = New CDO.Message

'Enable SSL Authentication
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

'Make SMTP authentication Enabled=true (1)
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'Set the SMTP server and port Details
'Get these details from the Settings Page of your Gmail Account
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smtp.gmail.com" 'I have also tried with the domain smtp.CompanyX.com
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'I have also tried 465,587
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Set your credentials of your Gmail Account
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = _
Application.Username
Mail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = _
InputBox("Enter Password")
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

higrm

New Member
Joined
Nov 5, 2014
Messages
47
It may be a firewall issue. I've got problems with some of my add-ins when moving from home to the office. Only after logging on and actually getting past the firewall to an IE website will my add-in successfully pull in web data.
 

Watch MrExcel Video

Forum statistics

Threads
1,089,973
Messages
5,411,586
Members
403,380
Latest member
ifog671

This Week's Hot Topics

Top