How to send an email attachment with a command line

Process Flow image by Christopher Hall from Fotolia.com

The ability to send an e-mail attachment from the Windows command line or a batch file can be very helpful in work flow automation and eliminating manual repetition. The Simple Mail Transfer Protocol's attachment implementation is complex. Third-party utilities such as Postie can send attachments using a single command that otherwise would be a lengthy block of scripting language code. Postie has a free version for small attachments and has been widely used since 2001. Other vendors with similar products include Febooti, Codestone and NetMailBot.

Download Postie Personal Edition or Commercial Trial (WIN32) from the Infradig Systems website at infradig.com.

Extract all of the files and folders contained in the postie.zip file to a location on your Windows-based computer such as C:\Temp.

Identify an attachment file on your local hard drive that is smaller than 256 KB and note the full path to the file. For example:

C:\Temp\Photo.jpg

Identify an SMTP server address that is accessible from your computer's Internet connection. Often it will be your Internet Service Provider's domain name appended to "smtp" and separated by a period. For example, if your ISP's domain name is "isp.com," then the SMTP server address may be:

smtp.isp.com

You will often find this address in your e-mail client's account settings.

Open Notepad or another text editor on your computer.

Copy the following command template text and paste it into your text editor. Ensure that it all appears on a single line.

\postie\postie.exe -host: -to: -from: -s:"" -a:"" -msg:""

Replace all of the data tags in the command text, which are encased with "<>."

-- Replace with the full path to the location where you extracted postie.zip, such as C:\TEMP.

--Replace with the full address of the previously identified SMTP server. Using our example, you would replace it with smtp.isp.com.

--Replace with the email address that you want to send the attachment to.

-- Replace with the email address that you want the attachment to appear from.

-- Replace with the text that you want to appear in the email subject line.

-- Replace with the full path to the previously identified attachment file, such as C:\Temp\Photo.jpg.

-- Replace with the text that you want to appear in the email message body.

Save the text document with a .bat extension to a location on the local hard drive and then run the batch file. If you entered everything correctly, the email should be sent with the attachment. As an alternative, copy and paste the full command text directly into the command line utility or the start-run box in Windows and run it from either of those places.

Most recent

×