the message cannot be sent to the smtp server. the transport error was xxxxxx. the server response was not available

Hello Experts
I am trying the simple vbscript to send emails from the server without SMTP service, we had STMP service on this server earlier but now we have migrated to google apps for email service.
No emails are going out from the server now which was using old server details, I am trying to test with simple script to see if I can send any email using gmail acnt details but having no luck yet ..
I am now getting the following error message when I use the attached script to send a test email

>>the message cannot be sent to the smtp server. the transport error was xxxxxx. the server response was not available

Please can someone advise?


Sub SendEmailGMail(sSubject, sEmailText, sGmailEmailAddress, sGmailPassword, sTo)
    Set oEmail = CreateObject("CDO.Message")
    oEmail.From = sGmailEmailAddress
    oEmail.To = sTo

    oEmail.Subject = sSubject
    oEmail.HTMLbody = sEmailText

    sSchema = ""
    oEmail.Configuration.Fields.Item(sSchema & "sendusing") = 2
    oEmail.Configuration.Fields.Item(sSchema & "smtpserver") = ""
    oEmail.Configuration.Fields.Item(sSchema & "smtpserverport") = 465
    oEmail.Configuration.Fields.Item(sSchema & "smtpauthenticate") = 1
    oEmail.Configuration.Fields.Item(sSchema & "sendusername") = sGmailEmailAddress
    oEmail.Configuration.Fields.Item(sSchema & "sendpassword") = sGmailPassword
    oEmail.Configuration.Fields.Item(sSchema & "smtpusessl") = 1
    oEmail.Configuration.Fields.Item(sSchema & "smtpconnectiontimeout") = 60

    Set oEmail = Nothing
End Sub

Open in new window

Who is Participating?
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
change below and try-
oEmail.Configuration.Fields.Item(sSchema & "smtpusessl") = True
I have tested the code and works fine...

When I gave wrong user name or password I get the above error, so check your credentials and try again.
yes, even I tried using the script and it works OK for me.
are you using with your gmail account or another domain account?
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

newbie27Author Commented:
Hello Folks,

Thanks for your input.


You caught me there, if I use the gmail email account to send email then its working ok.
However, when I use the company domain which is now managed via google apps, its not working with the email address.

The domain is now hosted on Gmail servers, however the email address still show as  instead of

I am using gmail service using their web interface to send and recieve emails using and it works to send and recieve, however, when i use the same account on the web server in my  test script, its failing.

Can someone advise how can I go about fixing this?

Can I use different from address in the script?

Please advise

Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
Change your port to 587 and try the same code.
newbie27Author Commented:
thanks folks it looks like, its working OK now. Please can someone advise what change do I need in the following code?

Public Shared Function SendEmail(ByVal From As String, ByVal ToField As String, ByVal Subject As String, ByVal Body As String, ByVal Attachment As Collection) As Boolean
        Dim Email As System.Net.Mail.MailMessage
        Dim MailServer As New System.Net.Mail.SmtpClient
        Dim MailServerAddress As String = ConfigurationManager.AppSettings("MailServer")
        Dim AdminEmail As String = ConfigurationManager.AppSettings("AdminEmailAddress")


            Email = New System.Net.Mail.MailMessage(From, ToField, Subject, Body)
            Email.From = New System.Net.Mail.MailAddress(From, "Customer Service")
            For i As Integer = 1 To Attachment.Count
                Email.Attachments.Add(New System.Net.Mail.Attachment(Attachment(i)))
            MailServer = New System.Net.Mail.SmtpClient(MailServerAddress)
            MailServer.Credentials = New Net.NetworkCredential("websitesender", "xCvfKa!")

        Catch ex As Exception
            MailServer = New System.Net.Mail.SmtpClient(MailServerAddress)
            MailServer.Credentials = New Net.NetworkCredential("websitesender", "xCvfKa!")
            MailServer.Send(AdminEmail, AdminEmail, "Web Site SendEmail error", "From: " & From & ", To: " & ToField & "Subject: " & Subject & ex.ToString)
            Return False
        End Try

        Return True
    End Function

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.