PDA

View Full Version : eMail sending code from script



abdulaziz
07-30-2015, 11:57 AM
Sir,
The following code i collected from the tutorial and pasted in a script. but no messages are sending this code. Any configuration problem or other mistake in this code? Kindly guide me.

Thanks & Regards
Abdul Azeez







Dim EmailTo
Dim EmailSubject
Dim EmailBody
Public Sub main()
EmailTo ="support@greenredsignal.com"
EmailSubject = "Test Email"
EmailBody = "This is a test email"


EmailFrom = "pairtrader1251252@gmail.com"
EmailFromName = "Pair Trader Script"
SMTPServer = "smtp.gmail.com"
SMTPLogon = "pairtrader1251252"
SMTPPassword = "***********"
SMTPSSL = true
SMTPPort = 465
cdoSendUsingPort = 2 'Send the message using SMTP over TCP/IP networking.
cdoBasic = 1 ' BASIC clear text authentication
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = EmailSubject
objMessage.From = """" & EmailFromName & """ <" & EmailFrom & ">"
objMessage.To = EmailTo
objMessage.TextBody = EmailBody

' Second, configure the server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2


objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer


objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic


objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPLogon


objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPPassword


objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort


objMessage.Configuration.Fields.Update


objMessage.Send
msgbox ErrorDescription(GetLastError())
End Sub

Rawan-HS
07-31-2015, 09:06 AM
Dear Abdulaziz :)


try the bellow code if not working , it will be the security issues from your Google mail ,
follow this link (https://myaccount.google.com/intro/security) and turn off the (2-Step Verification) from your gmail setting




Public Sub main()
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "pairtrader1251252@gmail.com"

emailObj.To = "support@greenredsignal.com"

emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "pairtrader1251252"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "***********"
emailConfig.Fields.Update
emailObj.Send
End Sub