How to Send Email from a Batch File Video

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: What is a Batch File? - Examples & Basics

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 0:01 Batch Files & How They Work
  • 0:41 How Email is Sent
  • 1:35 Method 1: Third-Party Mailers
  • 2:39 Method 2: Using VBScript
  • 4:00 Method 3: PowerShell
  • 5:07 Lesson Summary
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Speed Speed
Lesson Transcript
Instructor: John Weber

John has taught at the career college level, teaching courses in information systems. He holds a Master's Degree in Information Systems.

In the information technology field, we may be asked to complete a set of tasks and then create a notification when the tasking is done. This tasking is usually done with batch or script files, which we'll learn about here.

Batch Files & How They Work

Batch files or scripting files, are special files that allow us to execute several commands through a single file. These files usually perform such tasks as logging into a server, mapping drive letters, moving files, running special reports, or some other set of commands that performs a function. Sending an email as part of the batch process allows for the notification of both errors and notification of start and completion. In order for us to send an email using the batch process, we must understand the basics of how email is sent, the options for sending email from batch files and how to code the options.

How Email Is Sent

Email is essentially a specially formatted text message. In order to send it, an email must have a 'send to' address and either a subject or body of the message. When an email is composed and sent, a specialized command set tells the Simple Mail Transport Protocol (SMTP) server to build the email and resolve the recipient address with a Domain Name Server (or DNS). It also tells the SMTP to contact and send the email to the recipient server over the Internet.

In order for us to send an email via a batch or scripting file, we need know the address of the SMTP server for our organization and if we need any specialized permissions. Once we have this information, we can then begin to add send email functionality to our automated batch processes through one of the three common methods.

Method 1: Third-Party Mailer

Third party mailers act like the sending part of an email client, such as Microsoft Outlook. They are configured to connect to an organization's SMTP server to send email as if they were a client. The format for sending via the command or batch line is similar. In this example, we'lll using Blat to send the text output of the batch run to

Calling the Blat program from a batch file
Calling BLAT from batch file

Here, the -server is the authorized sending server for the organization. The -u and -pw switches represent the authorized username and password of a user who has rights to send email from the server named in -server.

The third-party mailer works well in this situation. Each mailer program has its own set of configuration settings that define how to setup and send emails. Some mailers allow attachments but others don't. Careful consideration must be made when choosing a solution for your organization.

Method 2: Using VBScript

VBScript is a scripting language that is similar to the Visual Basic programming language and can be written to perform many of the same functions that batch files do. It was designed by Microsoft to compete with other scripting languages, such as Java, and runs in the Windows Script Host (or WSH) environment.

In order to use VBScript to send an email from a batch file, the VBScript needs to be written and saved first. Once the VBScript is written and tested, the call to the Windows Script Host can be made from the batch file line.

Using VBScript to send an email
VBscript to send email

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account