How to send an email attachment with a command line

Written by james dalton
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to send an email attachment with a command line
Sending attachments from the command line can enhance work flow implementations. (Process Flow image by Christopher Hall from

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.

Skill level:

Things you need

  • Windows-based computer
  • SMTP server address accessible from your computer
  • Postie SMTP utility from Infradig Systems
  • Notepad or other text editor

Show MoreHide


  1. 1

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

  2. 2

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

  3. 3

    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:


  4. 4

    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 "," then the SMTP server address may be:

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

  5. 5

    Open Notepad or another text editor on your computer.

  6. 6

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

    <POSTIEPATH>\postie\postie.exe -host:<SMTPSERVER> -to:<TOADDRESS> -from:<FROMADDRESS> -s:"<SUBJECT>" -a:"<ATTACHMENTPATH>" -msg:"<MESSAGEBODY>"

  7. 7

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

    <POSTIEPATH> -- Replace with the full path to the location where you extracted, such as C:\TEMP.

    <SMTPSERVER> --Replace with the full address of the previously identified SMTP server. Using our example, you would replace it with

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

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

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

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

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

  8. 8

    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.

Tips and warnings

  • Ensure that the quotation marks within the command template are not removed. Remove the "" characters when replacing the data tags. The following is a fully populated sample command:
  • C:\temp\postie\postie.exe -s:"Attachment Test" -a:"C:\Temp\Photo.jpg" -msg:"Please find the attached file."
  • The SMTP server that you use must allow e-mails to be sent from your domain name. It is always safest to use an SMTP server provided by your ISP and to use a that uses your ISP's domain name, to minimise the risk of message rejection.
  • The free personal version of Postie allows for attachment sizes of only up to 256 KB and has other functional limitations. If you need to send larger attachments or want advanced features, purchase a commercial license for Postie or another similar utility.
  • When using Notepad, change "Save as type" to "All Files" when you save the batch file for the first time, or it will get saved as a .txt file and not execute when you run it.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.