VBScript help

sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
Looking for some help on a vbscript I have been using for years that suddenly stopped working a couple days ago. Here is the background -

I run this little script on my home computer via Task Scheduler, it runs once per hour on the hour from 6AM-5PM. I use it to send an email to myself at work to make sure outside mail is working. If I don't get an email at the top of the hour I make a quick check of everything. It's useful especially when a user says they are expecting an email from an outside source and haven't gotten it, I can at least verify that the problem probably is not a universal outage. So anyway, here is the script, minus the specific emails/server/recipient information:
SMTPServer = "mail.MY-ISP.net"
Recipient = "sprkymrk@myworkemail.com"
From = "my.home.email@MY-ISP.net"
Subject = "External Email Test"
Message = "This is a test message to verify email functionality from outside." 

GenericSendmail SMTPserver, From, Recipient, Subject, Message 

' Begin Sub
' ------------------------------------------------------------------
' Generic function to send mail using a remote
' SMTP server. Pass SMTPserver, From address, 
' Recipient address, Subject, and Message as arguments
' ------------------------------------------------------------------
Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message) 

set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message


msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

msg.Configuration.Fields.Update

msg.Send

End Sub

The error I get is on the line with "msg.Send". For the last two days it kicks up the error:
"The transport failed to connect to the server".
Code 80040213
Source CDO.Message.1

Help! Thanks! :)
All things are possible, only believe.

Comments

  • thesemantheseman Member Posts: 230
    Interesting, this works fine for me. ISP SMTP problems perhaps? I'm assuming you sent a test email without the script thru your ISP?

    -Travis
  • thesemantheseman Member Posts: 230
    Just tried something else:

    The DSL provider I have only allows you to send email from their network. I connected to the local cable provider and attempted to send thru the DSL SMTP server and it returned your listed error.

    I would then assume it is an issue with the ISP, not the script itself.


    -Travis
  • sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
    Thanks for checking it out for me. AFAIK nothing has changed on the ISP side. I can still send and recieve email, using those same settings, from an email client like Outlook or OE. It just won't work with the script. I can launch the script and watch it fail. Then I can open Outlook and using the same ISP and email address I can send/receive just fine. It's worked for about 3 years and once in a while it would fail if the DSL modem hicupped, but otherwise was just fine. Then about 2 days ago it just plain won't work. icon_confused.gif

    But I agree, it would seem to be more of a problem with the ISP. Maybe they started requiring authentication in order to send, as I do (and always have had) that setting checked in Outlook. I'll have to see if I can script a new mail message using Outlook, or find a way to authenticate in my script.

    I am open to other ideas.
    All things are possible, only believe.
  • thesemantheseman Member Posts: 230
    Came across this script to send the credentials for SMTP servers that require authentication. Might be worth a shot!!!

    EDIT: Just tested both on my home network, with an ISP that does not require authentication. Both scripts work, so can't really test the authentication part of this one.

    -Travis
    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory. 
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network). 
    
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
    
    Set objMessage = CreateObject("CDO.Message") 
    objMessage.Subject = "Example CDO Message" 
    objMessage.From = """Me"" <me@home.com>" 
    objMessage.To = "me@work.com" 
    objMessage.TextBody = "This is some sample message text.." & vbCRLF & "It was sent using SMTP authentication."
    
    '==This section provides the configuration information for the remote SMTP server.
    
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
    
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
    
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
    
    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
    
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    
    objMessage.Configuration.Fields.Update
    
    '==End remote SMTP server configuration section==
    
    objMessage.Send
    
  • sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
    Thanks for that theseman, I'll test it out this afternoon and let you know. :)
    All things are possible, only believe.
  • sprkymrksprkymrk Member Posts: 4,884 ■■■□□□□□□□
    Works great, thanks for finding that theseman. It is much appreciated. :)
    All things are possible, only believe.
  • thesemantheseman Member Posts: 230
    No problem, I can't write the stuff, but I am pretty good at finding what I need! lol.

    -Travis
Sign In or Register to comment.