www.collazo.ws

A little nothing about something

Putting subject & from in mail from command line

I couldn’t figure out how to send an email with both the subject and from set from the command line.

  1. mail -s "my subject" example@foo.bar

worked with mail but would only set the subject.

  1. sendmail -f "sender@foo.bar" receiver@foo.bar

worked with sendmail but would only set the “from”. With a little help from Google I put this together:

  1. #!/bin/bash
  2.  
  3. HOST=`hostname | awk 'BEGIN { FS="." } ; {print $1}'`
  4. DOMAIN=`hostname`
  5.  
  6. PASSWORD='mypassword'
  7.  
  8. BODY=`tail -n 40 /var/log/maillog`
  9.  
  10. FROM="$HOST@$DOMAIN"
  11. TO='receiver@foo.bar'
  12. SUBJECT="Last 40 lines of maillog"
  13.  
  14. (
  15. echo "From: $FROM"
  16. echo "Subject: $SUBJECT"
  17. echo "To: $TO"
  18. echo "$BODY"
  19. ) | sendmail -f $FROM $TO
Share and Enjoy:
  • Digg
  • Reddit
  • Slashdot
  • StumbleUpon
  • del.icio.us
Thumbs DownThumbs Up (No Ratings Yet)
Loading ... Loading ...

. This entry was posted on Friday, July 13th, 2007 at 1:56 pm and is filed under Code, E-Mail. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply



XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

It may take some time for your comment to appear, it is not necessary to submit it again.