How do I Send Email from the Command Line? How do I Send Email from the Command Line? linux linux

How do I Send Email from the Command Line?


$ echo "This is the email body" | mail -s "This is the subject" me@email.com

Alternatively:

$ cat | mail -s "A few lines off the top of my head" me@here.comThis is where mymultilinemessage would go^D

^D - means press ctrl+d


You can use mail:

$mail -s <subject> <recipients>

You then type your message and end it with a line that has only a period. This signals you are done and sends the message.

You can also pipe your email in from STDIN and it will be sent as the text of an email:

$<mail-generating-program> | mail -s <subject> <recipients>

One small note with this approach - unless your computer is connected to the internet and your DNS settings are set properly, you won't be able to receive replies to your message. For a more robust command-line program you can link to your POP or IMAP email account, check out either pine or mutt.


You can also use this sendmail version for windows. It is very simple to use, standard UNIX-like behavior. Fast. Does not need any installation, just call the EXE wherever it is located on your system.

Composing the email:

echo To: you@example.com, me@example.com >> the.mailecho From: them@example.com >> the.mailecho Subject: This is a SENDMAIL notification >> the.mailecho Hello World! >> the.mailecho This is simple enough. >> the.mailecho .>> the.mail

Sending the file:

\usr\lib\sendmail.exe -t < the.mailtype the.mail | C:\Projects\Tools\sendmail.exe -t