9
Jul 2010

How to Send an Email from the Command Line

At 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.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.