Need Help Sending smtp mail from a VBS Script

Answered Need Help Sending smtp mail from a VBS Script

  • Tuesday, February 05, 2013 11:52 PM
     
     

    I have a vbs script which emails files to my account.  It works for yahoo and gmail but not for hotmail.  The relevant code is:

    If Wscript.Arguments.Count = 1 Then
        Mailer = Wscript.Arguments(0)
    Else Mailer = "yahoo"
    End If

    Select Case Mailer
    Case "yahoo"
        Mailer = "smtp.mail.yahoo.com"
        Sender = "<useracct>@yahoo.com"
        Password = "<password>"
        Port = "465"
    Case "gmail"
        Mailer = "smtp.gmail.com"
        Sender = "<useracct>@gmail.com"
        Password = "<password>"
        Port = "465"
    Case "hotmail"
        Mailer = "smtp.live.com"
        Sender = "<useracct>@hotmail.com"
        Password = "<password>"
        Port = "587"
    End Select

    Dim objMail
    Set objMail = CreateObject("CDO.Message")
    objMail.From = Sender
    objMail.To = "<useracct>@yahoo.com"
    objMail.Textbody = ""
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Mailer
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendusername") = Sender
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Password
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Port
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    objMail.Configuration.Fields.Item _
        ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

    Function MailCriticalFile(MailSubject,CriticalFile)
        objMail.Subject = MailSubject
        objMail.Attachments.DeleteAll()
        objMail.AddAttachment CriticalFile
        objMail.Configuration.Fields.Update
        objMail.Send
    End Function

    MailCriticalFile "<Mail Subject>","C:\Users\<file>"

    Set objMail=Nothing
    Wscript.Quit

    As noted, when run with yahoo or gmail as the parameter the files are mailed.  When run with hotmail, I get a window:

    Error: The transport failed to connect to the server.

    Code: 80040213

    I've verified the username and password by logging in to hotmail (and to this forum) so am wondering if some other parameter needs to be set.  I've tried port 25 but that didn't make a difference.

    Any ideas?

All Replies

  • Wednesday, February 06, 2013 2:18 AM
     
     

    Can't bedoen with hotmail accounts.  Hotmail is not SMTP.


    ¯\_(ツ)_/¯

  • Wednesday, February 06, 2013 2:42 AM
     
     

    Further investigation shows you need to use port 25 and SSL.

    To test easily use PowerShell Send-MailMessage command:

    send-mailmessage -UseSsl -From jsmith@hotmail.COM -Body hello -SmtpServer smtp.live.com -Subject test -to jjone@hotmail.com -credential


    ¯\_(ツ)_/¯

  • Wednesday, February 06, 2013 3:01 AM
     
     
    If you are on a Verizon network or cross a Verizon network you will have to use port 587 by adding -port 587

    ¯\_(ツ)_/¯

  • Wednesday, February 06, 2013 5:40 AM
     
     

    My script has smtpusessl = True , so ssl should be begin used.

    I don't have PowerShell so can't try this test.

    Most of the web searches I've checked say use Port 587.  As I noted, I've tried both 587 and 25.

  • Wednesday, February 06, 2013 6:27 AM
     
     Answered

    It works fine for me.  Are you sure you have an smtp account on live and that your IP is not on a blacklist? Have you tried telnet.

    telnet smtp.live.com 25 )or 587)

    This should connect and display the servers welcome message like below:

    220 BLU0-SMTP320.phx.gbl Microsoft ESMTP MAIL Service, Version: 6.0.3790
    ready at  Tue, 5 Feb 2013 22:25:46 -0800


    ¯\_(ツ)_/¯