Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

VBA for sending text message from Gmail to Hotmail

0

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

Answer
Discuss

Discussion

Hi there, please put CODE tags around your VBA so it's easier to read. Are you trying to go directly through Gmail or Hotmail or are you managing those accounts through Outlook? I ask, because, it might be more reliable to manage and send the emails via Outlook.
don (rep: 1989) Oct 15, '18 at 4:48 am
Hi,
I want whenever I run the macro, gmail automatically sends the required mail to hotmail account via excel file. Please find attached vba codes file.
Regards,
Akash Sharma 
Akash Sharma (rep: 40) Oct 15, '18 at 2:03 pm
To enclose the code in your question in "code tags", edit your question, select the code, and click on the CODE button in the posting panel's header. Then click Update toor Submit Post save the change. I recommend to delete your "Answer" because it isn't an Answer and may prevent others from giving you a solution when they see that you already have an answer.
Variatus (rep: 4889) Oct 15, '18 at 9:06 pm
Akash, you didn't answer my question. Do you have Outlook on your computer and will you manage your gmail account via Outlook? If you do, then you can manage everything through Outlook and I think that will make things easier for you.
don (rep: 1989) Oct 17, '18 at 2:29 am
Hi I am not using outlook and I did not understand the use of code tags. I will delete my answer, request you to please view the file attached in my answer in which I have mentioned the codes I used for vba, kindly correct me what is missing in the codes file. As when I run the macro, nothing happens, Gmail account is unable to automatically send a mail to my hotmail account as mentioned in the codes file. 
Warm Regards,
Akash Sharma
Akash Sharma (rep: 40) Oct 19, '18 at 2:21 pm
Add to Discussion

Answers

0

Hi, please find enclosed codes used.

Regards,

Akash

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login