WSH VBScript Help

Discussion in 'Software' started by GreenKnight, Nov 26, 2003.

  1. GreenKnight

    GreenKnight Private E-2

    I have two problems (both are probably really easy fixes) :

    1) I am having trouble getting either the CDONTS.NewMail or
    CDO.Message objects to work properly.
    2) I need to know what the new line escape character is for
    VBScript

    I am Running Windows XP Pro with IIS's SMTP service installed.
     
  2. Kodo

    Kodo SNATCHSQUATCH

    1. What error message are you getting.

    2. New line = \n
     
  3. GreenKnight

    GreenKnight Private E-2

    No Error

    The problem is that there is no error reported. but no Mail message sent either (that I can tell) I will double check IIS but I am pretty sure it is working correctly.
     
  4. Kodo

    Kodo SNATCHSQUATCH

    check your SMTP mail folder see if it has backed up bad mail. The mail folder is in the Inetpub directory.
     
  5. GreenKnight

    GreenKnight Private E-2

    BadMail

    It has 57 messages, so I guess it must be a problem with IIS. Just to be sure, I am attaching a copy of the mail function I wrote.
     

    Attached Files:

  6. Kodo

    Kodo SNATCHSQUATCH

    open up one of the e-mails and see what data was created and what is missing.. this will help you determine what the problem is.
     
  7. GreenKnight

    GreenKnight Private E-2

    I deleted all of the files from the badmail directory (as they were old test messages) and reran the script twice. No bad file was created nor was any message sent.
     
  8. Kodo

    Kodo SNATCHSQUATCH

    are you using " ON ERROR RESUME NEXT" at all before you hit the function?

    does the script time out?

    is the smtp service running and is the smtp server on?
     
  9. GreenKnight

    GreenKnight Private E-2

    I am not Using On Error Resume next, nor does the script time out. I dont think it is a problem with the function as I just looked at the queue folder and saw 2 messages waiting to go out. The services are all running. Also, I must be using the newline character incorrectly, because when I put it inside quotations, it obviously won't work, but I get an error when I attempt to format it as below:

    Dim strIHateVBScript
    'this one gives an error
    strIHateVBScript = "I am getting annoyed" & \n "at this point"
    'and so does this one
    strIHateVBScript = strIHateVBScript & \n & "error"
     
  10. Kodo

    Kodo SNATCHSQUATCH

    try VBCRLF for line feed instead.

    if there is mail pending then it should be sending.. I didn't see anything wrong with your function either which is why I'm shooting for other reasons. Check your event manager and see if there is anything out of ordinary.

    Are you using your email address in the from and to lines so you can test properly?
     
  11. GreenKnight

    GreenKnight Private E-2

    Forgive my ignorance, but what is VBCRLF?

    Also, you are right it has to be a problem with IIS, which I am sure I can fix, I just haven't had time to troubleshoot properly. I appreciate you looking at my function as I am new to VBScript and as always I am diving in over my head :) but then again that is the best way to learn
     
  12. Kodo

    Kodo SNATCHSQUATCH

    I normally do VBA and ASP so my standard VBscript knowlege is only going off my experience with the former.

    VBCRLF is Visual Basic Carriage Return Line Feed.

    instead of using \n .. just use & VBCRLF &
     
  13. GreenKnight

    GreenKnight Private E-2

    just to let you know, with VBScript and WSH 5.6, you have to use

    VBCrLf (case sensitive). Thanks for all the help. Also, I found out that it is a problem with Windows XP's SMTP server. I ran the same script on a windows 2003 box with smtp configured and it worked perfectly. Now I just have to figure out why..
     
  14. Kodo

    Kodo SNATCHSQUATCH

    you know why? because CDONTS doesn't exist on windows XP.. DOH!! I totally forgot.. you need to copy the CDONTS.SYS file from win2k to xp..
     
  15. GreenKnight

    GreenKnight Private E-2

    I am using CDO.Message though and it is creating the mail, but it is having trouble routing it. (I see the mail in the badmail directory) It has to be something with DNS. Both Win2k3 boxes i ran the script on are configured as DNS servers as well. I am trying now to create a domain in the WinXP SMTP service that is configued to use a remote DNS server
     
  16. Kodo

    Kodo SNATCHSQUATCH

    silly me.. I forogt that the emails were being created.. please disregard my brain fart.. :D
     
  17. GreenKnight

    GreenKnight Private E-2

    Any Idea on how to send a CDO message using a remote SMTP Server?
     
  18. Kodo

    Kodo SNATCHSQUATCH

    'Sending a text email using a remote server

    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "Example CDO Message"
    objMessage.Sender = "me@my.com"
    objMessage.To = "test@paulsadowski.com"
    objMessage.TextBody = "This is some sample message text."

    '==This section provides the configuration information for the remote SMTP server.
    '==Normally you will only change the server name or IP.

    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") = "smtp.myserver.com"

    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==

    objMessage.Send
     
  19. GreenKnight

    GreenKnight Private E-2

    I get a compilation error at the following line (says invalid character
    .Configuration.Fields.Item_("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
     
  20. Kodo

    Kodo SNATCHSQUATCH

    the underscore
     
  21. GreenKnight

    GreenKnight Private E-2

    One Last Question. I am Using CDO.Message to send email using a remote SMTP server (thanks for that code by the way) and I am having trouble getting files to attach. any suggestions?

    Sub sendMail(fileName1, filename2, filename3)

    Dim arrInfo
    Dim Message
    arrInfo = readInList(facilityLoaction)

    strMessBody = arrInfo(4)

    Set Message = CreateObject("CDO.Message")
    With Message
    .To = arrInfo(2)
    .Subject = arrInfo(3)
    .TextBody = strMessBody
    .From = arrInfo(1)
    .AddAttachment filename1
    .AddAttachment filename2
    .AddAttachment filename3
    End With
    Message.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    'Name or IP of Remote SMTP Server
    Message.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = arrInfo(5)
    'Server port (typically 25)
    Message.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    Message.Configuration.Fields.Update
    Message.Send
    Set Message = Nothing

    End Sub
     
    Last edited: Dec 9, 2003

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds