none
VB Script Issue : Carriage Return not working RRS feed

  • Question

  •  Hi Folks -

    Trying to setup an email script but having trouble with a carriage return.

    I"m calling the VB from batch as such:

    @ECHO OFF
    cd /d %~dp0
    
    SET "GJA_PROCPATH=C:\path\"
    SET "FN=filename.txt"
    
    ::
    SET "TEXT=HFM Extract File : %FN%"
    SET "SRVR=smtp.client.net"
    SET "FROM=client.OracleSupport@client.com"
    SET "DIST=joe.shmoe@client.com; RlgyMgdSvcs@firm.com"
    
    CSCRIPT "%VBS_BIN%Email_Utility.vbs" "%GJA_PROCPATH%" "%FN%" "%TEXT%" "%SRVR%" "%FROM%" "%DIST%"
    pause


    And then here is my VB :

    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'
    '::-- Script Name: Email_Utility.vbs											  --::'
    '::-- 																			  --::'
    '::-- Description: This script used to email									  --::'
    '::--                															  --::'
    '::--																			  --::'
    '::-- Calls:       																  --::'
    '::-- Called By:   Any script needing to email									  --::'
    '::-- 																			  --::'
    '::-- Parameters:  Called by <file> to get arguments to determine:				  --::'
    '::--																			  --::'
    '::--              1. Path to attachment										  --::'
    '::--              2. Attachment												  --::'
    '::--              3. Text [ Email and Subject]									  --::'
    '::--              4. SMTP Relay Server											  --::'
    '::--              5. From email												  --::'
    '::--              6. Distribution list										      --::'
    '::--														                      --::'
    '::--    																          --::'
    '::-- Author:      Authose						          --::'
    '::-- Date:	       05/11/2018                                                     --::'
    ':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::'
    
    Dim mText, strSafeDate, strSafeTime, eAttachFile
    Dim PATH, FILE, TEXT, SRVR, FROM, DIST
    
    Set args = Wscript.arguments
    PATH= args(0)
    FILE= args(1)
    TEXT= args(2)
    SRVR= args(3)
    FROM= args(4)
    DIST= args(5)
    
    mText=""
    strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
    strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
    
    mText=mText + "Attached is the " + TEXT 
    mText=mText + "Run as of: " & strSafeDate & "-" & strSafeTime + CHR(13)
    mText=mText + CHR(13)+CHR(13)
    
    
    WScript.Echo mText
    WScript.Sleep 20000
    
    Set objEmail = CreateObject("CDO.Message")
    
    objEmail.Subject = TEXT 
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SRVR
    objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    
    objEmail.AddAttachment eAttachFile
    
    objEmail.From = FROM
    objEmail.HTMLbody = "<html><body><pre>" & Text & "</pre></body></html>"
    objEmail.To = DIST
    
    objEmail.Send

    I need to add CHR(13) to line 39 in my VB script.  But when I do, it cuts off most of the first value that gets set with mText and jsut displays the Run as value, first...which is weird.

    What am I missing? Any help is greatly appreciated. Thank you!


    • Edited by cdtakacs1 Sunday, May 13, 2018 5:29 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 7:54 PM Abandoned
    Sunday, May 13, 2018 5:25 PM

All replies

  • If i add this it works:

    eText=eText + "Attached is the " & TEXT & vbCrLf

    Is that best practice, though?

    Sunday, May 13, 2018 5:36 PM
  • As noted, you need to use a carriage return, chr(13), followed by a line feed, chr(10). In VBScript the built in constant is vbCrLf. The carriage return just returns to the beginning of the line.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Sunday, May 13, 2018 8:12 PM
  • Thank you - that worked like a charm!
    Monday, May 14, 2018 7:41 AM