Hi All,
I tried to create vba to send mail from Gmail to Hotmail Account via button in my excel file. However, when I click on the run button, I do not receive mail as instructed to the macro. I have enabled security settings in google account. Please find below codes and help me out with error that I am not able to find.
Sub send_email_via_gmail()
Dim myMail As CDO.Message
Set myMail = New CDO.Message
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smptauthenticate") = 1
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "akashsharma.mdumba@gmail.com"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
myMail.Configuration.Fields.Update
With myMail
.Subject = "Test Email from Mr. Akash Sharma"
.From = "akashsharma.mdumba@gmail.com"
.To = "akash_sharma16@hotmail.com"
.TextBody = "Hello Akash"
End With
On Error Resume Next
myMail.Send
'Msgbox(Mail has been sent")
setmyMail = Nothing
End Sub