Command Line Email in Cygwin

Logo of Cygwin

Cygwin (Photo credit: Wikipedia)

Cygwin provides a Linux-like environment on Windows, but unfortunately the heirloom mailx (aka nail) email utility is not included as a supported package. I previously recommended mailx for quick command-line email in Linux. For Cygwin users, a similar utility is included in the Cygwin “email” package. Thanks to Dean Jones and any other contributors for providing this useful tool. You can view the latest README and source code on the eMail GitHub repository. Here is an example for quick command-line email sending in Cygwin:

echo 'Test message body text. Sincerely, You' | 
email -V -f 'FromAddress@Domain.Com' -n 'From Name' 
-s 'Test Subject' -r 'SMTPServer.Domain.Com' 
-a 'FileToAttach.ext' 

This example assumes that you want to set a specific SMTP email server and from address on the command-line for your outgoing message. For full details, see the official project site and repository linked above. The tool does come with standard command-line help and a manual page. Good luck with quick email output on your Cygwin shell scripts :-).

About notesbytom

Keeping technology notes on to free up my mind to solve new problems rather than figuring out the same ones repeatedly :-).
This entry was posted in System Administration and tagged , , , , , . Bookmark the permalink.

14 Responses to Command Line Email in Cygwin

  1. Rahul says:

    I am getting the following error :
    email: FATAL: Could not connect to server: on port: 25: Operation not permitted.

    Please help me.

    • notesbytom says:

      According to the official Gmail support site, you will need to follow their SMTP connection requirements. Check out their settings at,1665144

      Some highlights: Requires TLS,, Port: 587 (465 not compatible), (SSL not compatible), Requires authentication: Yes, Full Name or Display Name: [your name], Account Name or User Name: your full Gmail address ( Google Apps users, please enter, Email address: your full Gmail address ( Google Apps users, please enter, Password: your Gmail password.

      If you need more info I would recommend contacting the Gmail support team directly.

  2. Josh says:

    Worked Awesome!! Thanks for the information!!

  3. jay says:

    email: FATAL: Smtp error: 550 5.7.1 Unable to relay

    SMTP server and port are configured as I’m able to send email using a python script using the same config.

    • notesbytom says:

      I would need more details to provide feedback. Do you have sample Python code and the matching sample email command you’re using? If all the parameters are the same I would expect both to function similarly unless there is some kind of defect you’re encountering.

  4. deanproxy says:

    Hi Tom,
    I’m the author of the email program. Thank you for doing this writeup.

    I wanted to clear up something for some gmail users. Use port 587 for TLS. Port 465 is SSL and will not work with my program. I support TLS only.

    I get a lot of support messages about this and since you took the time to do a great writeup, I figured I would piggyback off of it to help users out, if you don’t mind. 🙂

    Also, please feel free to log any bugs with it over on github!

    • Jörg (mx) says:

      Hello deanproxy, Thanks for your program. It works great!!!.

      Nevertheless, I’d like to add some ‘configurable’ thing on fields like ‘Subject’. i.e. I’d like to add a Date which is a variable inside my shell script, but writing this on the command line:
      echo “blablabla” | email -V -f ‘’ -s ‘This is my date: $date’ ….
      simply doesn’t take $date like a real date.

      Any ideas?

  5. Jörg (mx) says:

    Great!! thanks!!! quite an excelent program

  6. Jeff says:

    I’m having an issue where it sends the email to the correct recipient with the correct subject, but there’s nothing in the message body. I’ve tried a ton of different ways, but it will not write anything to the message body. Here’s by command:

    echo -c ‘Test message body’ | email -V -f “” -n “Sender Name” -s “Test Notification”

    • notesbytom says:

      Hello @Jeff, I’m not familiar with the “-c” option to echo. Perhaps that is causing a problem? Try using: echo TEST_MESSAGE_BODY | email …
      Where there are no quotes or options with the echo command just to make sure that’s not causing the trouble.

      • Jeff says:

        Thanks for the reply Tom! Turns out it’s our SMTP gateway that’s removing the message body. I’m working with Office 365 support to figure out what’s going on there, but when we switch our SMTP server to a different provider, it works fine. I’ll be sure to post to solution to our Office 365 problem once we figure it out

      • notesbytom says:

        Your Office 365 smtp gateway might be looking for a MIME-formatted message body, or other markers of well-formed mail messages that are less likely to be spam. See and maybe also consider copying a well-formed raw email generated by a known-good mail client acceptable to the Office 365 mail gateway (use as a template message body). Good luck with your project, let us know if you come up with a solution!

      • Dean Jones says:

        Also, if there are any issues such as headers that should be added to the application to make it more friendly with other mail servers, please file a bug report on the github page and I will add it as soon as I can. eMail is a very bare bone client and works pretty specifically off of the old RFC-891 standard, but I can update it to make it work a bit better for other mail servers.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s