PDA

View Full Version : Excel VBA - Send Email Error



alexnkc
07-08-2017, 12:31 AM
Hi,

Help needed on fixing the problem on sending email from Excel.
I try to send email (Hotmail or Gmail) from Excel. I do some google and reference code from google and do some modification to suit my need.
Below are the code that I use and it was not success with error (picture below)
I try and error to fix it (like change the Server Port, SSL -true/false,...) but could not solve it.


19693



Dim Hotmail_Prep As CDO.Message

Set Hotmail_Prep = New CDO.Message
With Hotmail_Prep
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smptauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.live.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 '25 '465 '587
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "***@hotmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "ZZZ"
.Update
End With

.Subject = "Test Email"
.From = "***@hotmail.com"
.To = "yyy@hotmail.com"
.TextBody = "Good morning!"
End With

'On Error Resume Next
Hotmail_Prep.Send
MsgBox ("Mail has been sent")

Set Hotmail_Prep = Nothing

Thanks,
KC

mancubus
07-10-2017, 11:35 PM
i use ms outlook it's included in the standard packages.

here are some search results:

https://social.msdn.microsoft.com/Forums/office/en-US/7e558cdf-25b9-415a-b6db-7815b0326099/unable-to-send-emails-using-gmail-smtp-server?forum=accessdev

https://stackoverflow.com/questions/41463936/smtp-vba-when-sending-mail-transport-failed-to-connect-to-server

http://www.vbforums.com/showthread.php?596162-The-Transport-Failed-to-connect-to-the-Server

alexnkc
07-11-2017, 03:40 AM
Hi manacubus,

Thanks for your reply.
I found the solution to send email with using Gmail account. But it was fail on Hotmail account.