How to Send an Email from the Command Line
Fri, 07/09/2010 - 16:13 — Sean CarneyAt work there is a running joke where my boss sends a late night work-related email and receives reprimands from others for working late - at an even more absurd time.
Since my Module 5 results will be released this evening I thought that I should send the announcement at some silly time like three in the morning. The only problem is I don't want to actually be awake and have to send the message at that time.
Luckily, I can schedule the email to be sent from my server using cron, assuming I can send it using a simple command. I've done some research and for your benefit (and mine) here is how to send an email from the command line.
echo -e "This is the body of the email. Use \n for line breaks" | mail -a 'From: "Your Name" <your-email-address@domain.com>' -s "This is the subject of the email" recipient@domain.com
You can add additional recipients by simply adding more at the end of the mail command. To add additional headers to the message add another -a 'your header here' to the mail command.
- 58 reads

Comments
Post new comment