Close Menu
Computing.net
    Facebook X (Twitter) Instagram
    Computing.netComputing.net
    • News
      1. AI
      2. Crypto
      3. Gaming
      4. Hardware
      5. Security
      6. Software
      7. View All

      Anthropic’s COBOL Automation Tool Triggers IBM Stock Plunge and Crypto Market Decline

      February 24, 2026

      AI Trading Bot Loses $441K in Crypto After Decimal Point Mistake

      February 23, 2026

      Tesla (TSLA) Stock: Goodbye Sedans, Hello Robots in Dramatic Production Shift

      January 29, 2026

      Palantir Technologies (PLTR) Stock: Why Bears May Be Wrong About Valuation Concerns

      January 29, 2026

      SUI Token Rallies 40% Following Major Staking Event and CME Futures Announcement

      May 12, 2026

      Chainlink (LINK) Surges to $10.40 as Network Activity Hits Eight-Month Peak

      May 12, 2026

      Dogecoin Whales Ramp Up Accumulation as DOGE Eyes Critical Breakout Levels

      May 12, 2026

      Bitcoin Holds $81K While Burry Flags Nasdaq Bubble and Oil Surges Past $105

      May 12, 2026

      Hamster Kombat: Unraveling TON’s Gaming Phenomenon

      August 7, 2024

      W-Coin: Exploring the Latest Telegram Tap-to-Earn Phenomenon

      August 7, 2024

      Hamster Kombat: 300 Million Players & Counting, HMSTR Token Airdrop Soon!

      July 31, 2024

      Hamster Kombat Developers Work with TON Team on Airdrop Solution

      July 30, 2024

      Nothing Expands Product Line with New AI Feature & Phone Update

      July 31, 2024

      Security Audit Reveals Concerns in Atari’s Blockchain Game on Base

      August 6, 2024

      SideWinder Group Targets Maritime Facilities in New Cyber Espionage Campaign

      July 30, 2024

      OAuth Implementation Flaw Exposes Millions of Websites to XSS Attacks

      July 30, 2024

      Hamster Kombat Players Face Growing Cybersecurity Threats

      July 25, 2024

      Anthropic’s COBOL Automation Tool Triggers IBM Stock Plunge and Crypto Market Decline

      February 24, 2026

      Cookie Crumble: Google Halts Plans to Eliminate Third-Party Cookies in Chrome

      July 23, 2024

      Big Brother is Watching: Apple’s Creepy New Ad Urges iPhone Users to Ditch Chrome

      July 23, 2024

      Nvidia Stock Soars to New Record at $219.44 Ahead of May 20 Earnings

      May 12, 2026

      Rocket Lab Shares Surge Past $120 Following Wave of Analyst Upgrades

      May 12, 2026

      GM Shares Decline Following 600 IT Layoffs Amid Strategic AI Workforce Transformation

      May 12, 2026

      SES Delivers €847M Q1 Performance as Intelsat Integration and Aviation Deals Fuel Expansion

      May 12, 2026
    • How To

      Batch Files: Tokens and Delimiters (FOR Loops)

      July 31, 2024

      Types of Ethernet Cabling & Electrical Low Voltage Wiring

      July 9, 2024

      What You Should Know About .JSON File Extension

      January 10, 2023

      Bkup File Extension

      November 19, 2022

      HEIC File Extension

      November 19, 2022
    • Office
      1. Excel
      2. Google Sheets
      3. View All

      How to Convert Column List to Comma Separated List in Excel

      July 24, 2024

      How to Find the Last Monday of the Month in Excel

      July 24, 2024

      Convert Bytes to MB or GB in Excel: 3 Methods!

      July 24, 2024

      How to Remove Characters from Right in Excel

      July 30, 2023

      How to Subtract in Google Sheets: Complete Guide

      July 31, 2024

      Bullet Points in Google Sheets

      January 20, 2022

      Sort by Date in Google Sheets

      January 18, 2022

      Google Sheets Timestamp

      January 17, 2022

      How to Subtract in Google Sheets: Complete Guide

      July 31, 2024

      How to Convert Column List to Comma Separated List in Excel

      July 24, 2024

      How to Find the Last Monday of the Month in Excel

      July 24, 2024

      Convert Bytes to MB or GB in Excel: 3 Methods!

      July 24, 2024
    • Answers
    • About
    • Contact
    Facebook X (Twitter)
    Computing.net
    How To

    How to Send Email From VBScript/Batch file

    Computing StaffBy Computing StaffSeptember 23, 2021
    Twitter LinkedIn Email Telegram
    How to Send Email From VBScript/Batch file
    Twitter LinkedIn Email Telegram

    Often I have to send emails of various logs and other details to myself and others. Just for this stuff logging on to the system ,collect the data, compose the email, Attach log file.. It take lot of time and efforts. Was wondering if a script can do the job for me.. Overall thats why scripting is ..

    Later i came across a VBScript logic which can send email for me.. It helped me a lot so thought lets write an article in simple terms explaining how you can use it to fulfill your needs .

    I tried to explain it in the way so anyone without knowing VB can use it..

    Let’s Take some real world scenarios where we can use it….

    #1: You perform a automated FTP upload job on a remote server/desktop and wondering where the upload was successful or not. For that you will have to login to the system and check per day.

    You can simply append this script into the script which performs the upload and once upload completes, it will send an email to you notifying the result or with the log file attached directly into your inbox.

    #2: You perform a scheduled automated Backup job on your systems in a network. Wondering whether the backup was successful or not. Deploy this script (u can customize it as you want) and where the backup was successful or not, you will receive the result in your inbox with the result and computer name in subject line itself. (U can easily Modify the script to accomplish this).

    Alright..Seems interesting. Lets see the script. Its VBScript.

    '=================================================
    'Script to send email… by Computing.net…...
    'Configuration Field,Modify below..

    SMTPServer = "yoursmtpserver_IP_OR_NAME"
    Recipient = "THE_EMAIL_RECIPIENT"
    From = "THE_EMAIL_FROM_ID"
    Subject = "Test email"
    Message = "THE EMAIL SUBJECT"
    attachment = "c:\test.txt"

    'If there is no attachment needed,Remove or comment above line.
    'To comment the line,just add " ' " before the line.
    'DO not modify anything below this line.

    GenericSendmail SMTPserver, From, Recipient, Subject, Message

    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.AddAttachment attachment
    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

    '===========================================

    Alright, That’s the script. Now how to use it:

    There can be many ways to use it. I will list some of them ..

    Call from a batch file

    Step 1. Create a text file in the same folder where the batch file is placed, Save it as sendemail.vbs

    Step 2. Paste the script In that text file and modify the configuration field as per your environment.

    Step 3. Call the script from a batch file like below:

    Cscript sendemail.vbs

    Append the script itself in the batch file so it will create the script in temp folder on the fly when you execute the batch.

    Step 1. Edit your batch file and add this line somewhere before you want to call the email script.

    type %0 | find /i ” ” | find /v “butnotthisline” >%temp%\sendemail.vbs

    Step 2. Call the script from the batch wherever you want, the command would be

    Cscript %temp%\sendemail.vbs

    Step 3. Add one more line in your batch script, just after your code ends and the Vbscript starts.

    GOTO :EOF

    Step 4. Above will extract the Vbscript from the batch file and then put in tempfolder.

    Step 5. Modify this script’s configuration field and then append in your original batch script after above line

    Step 6. Add 8 (or n number) of space before each line of the Vbscript part after :GOTO :EOD line

    The point here is , we have to append n number of space before each line and then extract all lines with those number of spaces from this batch file. SO, if you add 8 space here then make sure there is only 8 space exist between ” ” in step b above.

    Customization

    Now, What if you want to customize the email subject with your own variables like computername/date time or something else.

    Lets do that as well.. For that you have to modify the configuration field wisely.

    This is the configuration field.

    SMTPServer = "yoursmtpserver_IP_OR_NAME"
    Recipient = "THE_EMAIL_RECIPIENT"
    From = "THE_EMAIL_FROM_ID"
    Subject = "Test email"
    Message = "THE EMAIL SUBJECT"
    attachment = "c:\test.txt"

    Suppose, you want to change the subject to the computer name of the system from where the script is being executed. Modify the subject line as below.

    Subject = Wscript.Arguments(0)

    And now, Call the script from your batch like this.

    Cscript %temp%\sendemail.vbs “I want the subject as %computername%”

    Alright..Thats all for now.. Hope this is useful.

    Share. Twitter LinkedIn Email Telegram
    Avatar photo
    Computing Staff
    • Website

    Related Posts

    Batch Files: Tokens and Delimiters (FOR Loops)

    July 31, 2024

    Types of Ethernet Cabling & Electrical Low Voltage Wiring

    July 9, 2024

    What You Should Know About .JSON File Extension

    January 10, 2023

    Bkup File Extension

    November 19, 2022

    HEIC File Extension

    November 19, 2022

    Working with Batch variables and For loops

    October 6, 2021
    Add A Comment

    Comments are closed.

    Latest

    Nvidia Stock Soars to New Record at $219.44 Ahead of May 20 Earnings

    May 12, 2026

    Rocket Lab Shares Surge Past $120 Following Wave of Analyst Upgrades

    May 12, 2026

    GM Shares Decline Following 600 IT Layoffs Amid Strategic AI Workforce Transformation

    May 12, 2026

    SES Delivers €847M Q1 Performance as Intelsat Integration and Aviation Deals Fuel Expansion

    May 12, 2026

    Trump Dismisses Iran Peace Proposal — Oil Markets React as Hormuz Remains Restricted

    May 12, 2026
    • Facebook
    • Twitter

    Latest Reviews

    Meta Platforms Shares Tumble 8% Despite Strong Q1 Performance Amid AI Investment Surge

    April 30, 2026

    Flush.com Review: Casino & Sportsbook With 275% Welcome Bonus

    March 7, 2026

    Katsubet Review: Crypto Casino With 300% Welcome Bonus & Free Spins

    March 7, 2026

    7Bit Review: Crypto Casino With 325% Bonus & 250 FS

    March 7, 2026

    Mega Dice Review: Crypto Casino With 200% Bonus & 50 Free Spins, Legit?

    March 7, 2026


    Home / Privacy Policy / Terms & Conditions

    Computing.net © 1996 - 2026 Kooc Media Ltd. All rights reserved. Registered Company No.05695741

    Type above and press Enter to search. Press Esc to cancel.