Send Automated Emails Using SendEmail & Windows Task Scheduler

late   Send Automated Emails Using SendEmail & Windows Task SchedulerNo matter what your job is, usually everyone at some point has to email a boss or supervisor with daily, weekly or monthly status reports. A lot of time this is nothing more than sending over a spreadsheet of data, logfiles or other reports that are usually automatically generated.

Gathering the data and generating reports may not be a big deal for you, but remembering to write up that email every so often can turn into a real hassle. And if you forget once or twice, it looks like you’re not on top of your game.

This is where your computer comes in handy.


Most Windows users know about the Windows Task Scheduler by now. In this article, I’m going to show you how you can use Windows Task Scheduler in combination with the awesome SendEmail SMTP command-line tool to send off scheduled, automated emails that include multiple attachments.

Configuring SendEmail to Correctly Send Reports

The task here is fairly simple. You have a directory where several automated reports are stored. Maybe it’s a logfile summary for servers that you support, which you need to forward to your supervisor. Maybe it’s an Analytics traffic report that you need to forward to your website clients. Regardless of the need, this technique will let you automatically fire off an automated report email that will include as many of those attachments that you need to send. So long as you have a system set up to automatically update those files before the scheduled email goes out – you’ll have a completely automated reporting system.

Here’s how it works. Let’s say I send out three Google Analytics reports that I generate and download every Thursday and I store them in a directory called C:/Analytics. When you download SendEmail from the link above, there’s no setup required. Just place it in any directory where you’d like to run it from. In this case I’m just placing it in the same directory, so that I don’t have to include the directory path to the attachments in my command line.

sendmail1   Send Automated Emails Using SendEmail & Windows Task Scheduler

Linux users have been using the “sendmail” command for ages, so this isn’t really new to them, but the Windows compatible “SendEmail” tool is something that lets Windows users have the same sort of command-line functionality. Once you have the executable sitting in a directory like this, as long as you know the syntax, you can do a lot of cool stuff with the tool.

When you issue the “SendEmail” command at the command prompt (or run it from an application), you have to follow it with a number of parameters. The critical ones that we are concerned with are shown in the examples below.

  • -f xxxxx@gmail.com : This parameter is the email address that will be the “sender.”
  • -t rdube@yahoo.com : This is the recipient’s email address.
  • -u Monday Status Updates : This is the subject
  • -m Here’s the analytics data for this week! : This is the message body.
  • -a Analytics_Channel1.csv Analytics_Channel2.csv Analytics_Channel3.csv : These are the attachments.
  • -s smtp.gmail.com:587 : SMTP server and port
  • -xu xxxxx@gmail.com : SMTP authentication ID name
  • -xp A1ienz2A51 : SMTP authentication password
  • -o tls=yes : SMTP uses TLS (or SSL)

These are all of the parameters you’ll need to complete the task that I’m detailing in this article. Once you’ve downloaded the SendEmail.exe file to your computer, you’re ready to use Windows Task Scheduler to issue your SendEmail automated email command every day, week, or month.

Setting Up Windows Task Scheduler

Open up Windows Task scheduler by going to Start->Programs->Accessories->System Tools->Task Scheduler. Click to create a basic task.

sendmail2   Send Automated Emails Using SendEmail & Windows Task Scheduler

This will walk you through the task scheduling wizard, where you can assign any calendar schedule you’d like for these emails to get sent.

sendmail3   Send Automated Emails Using SendEmail & Windows Task Scheduler

On the next screen, select “Start a Program” and then you’ll see the screen where you need to set up the task. This is where you’ll enter the path for your SendEmail executable and the parameters.

sendmail4   Send Automated Emails Using SendEmail & Windows Task Scheduler

The entire argument line that I typed in was as follows:

-f xxxxx@gmail.com -u Monday Status Updates -m Here’s the analytics data for this week! -a Analytics_Channel1.csv -t xxxxx@yahoo.com -s smtp.gmail.com:587 -xu xxxxx@gmail.com -xp xxxxxxx -o tls=yes

Refer back to the parameter list above, but as you can see this sends out an email from your Gmail account to a recipient who has a Yahoo account with a subject line, “Here’s the analytics data for this week!” When this task runs (which will run every week), it fires off your message and attaches the file attachments that you’ve defined your parameters above.

This is what the received email looks like.

sendmail5   Send Automated Emails Using SendEmail & Windows Task Scheduler

As you can see, there’s no indication that it comes from an automated script. Instead, it has a personal message and the necessary data/information files attached to the email. So long as you make sure the files are updated before this email goes out, you’ll never have to worry about forgetting to send out another one of these status updates again. You can look as though you’re being extremely productive. Meanwhile, you can work on Saikat’s approach to being a procrastination ninja!

Have you ever used the command-line SendEmail tool for Windows? Or maybe you have a different method for sending out automated emails?  Share your own insight about this tool or other similar tools in the comments section below.

Image Credit: Tory Byrne

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

11 Comments -

Chris_Hunter

Ryan,

This is a GREAT tutorial on using these tools! Really great stuff!

Let me ask you a question or two: for the -m Message Body, is there a max limit of characters or words that can go there? What about the Subject Line? Max there as well?

Thanks!

Ryan Dube

Hey Chris, thanks!

Based on some of the comments in the FAQ, there is a known limit for the message of 16kb. You’ve stumped me on the subject line though – I don’t know!

Chris_Hunter

16kb is a good amount of plain text data. More than enough for a blog post! Thanks, Ryan!

Aibek

I second Chris, great tutorial!

Chris_Hunter

Ryan,

This is a GREAT tutorial on using these tools! Really great stuff!

Let me ask you a question or two: for the -m Message Body, is there a max limit of characters or words that can go there? What about the Subject Line? Max there as well?

Thanks!

Ryan Dube

Hey Chris, thanks!

Based on some of the comments in the FAQ, there is a known limit for the message of 16kb. You’ve stumped me on the subject line though – I don’t know!

EE

Can someone post an example line for a verizon.net email address? I’m having a hard time with this…

EE

Can someone post an example line for a verizon.net email address? I’m having a hard time with this…

Jeff

I’m getting this strange error when I try to use sendmail in command prompt:

Sep 22 15:05:06 sendemail[4872]: ERROR => Connection attempt to smtp.gmail.com:587 failed: IO::Socket::INET: connect: Unknown error

This is what i type:
C:Users>sendemail -f @gmail.com -u Subject test -m test
-t @gmail.com -s smtp.gmail.com:587 -xu
@gmail.com -xp -o tls=yes

Is this correct?

Jeff

I’m getting this strange error when I try to use sendmail in command prompt:

Sep 22 15:05:06 <computername> sendemail[4872]: ERROR => Connection attempt to smtp.gmail.com:587 failed: IO::Socket::INET: connect: Unknown error

This is what i type:
C:\Users\<username>>sendemail -f <username>@gmail.com -u Subject test -m test
-t <username>@gmail.com -s smtp.gmail.com:587 -xu <username>
@gmail.com -xp <password> -o tls=yes

Is this correct?</password></username></username></username></username></computername>

Ryan Dube

Hey Jeff, that looks correct to me. What version of Windows are you using and are you confident you have a good outside Internet connection that you can use normally to send mail out using the smtp server you identified?