Thursday, June 4, 2009

Quick mail post

Linux has an excellent command: mail, now who can guess what it does?

Anyway, I was searching how to send something with this today even though I've looked at this before, it somehow got screwed up.
We only have mail on our server (and sendmail, but that seems way more complicated) and we need to send an attachment and have a sender address.

After looking around for a while I found this:
uuencode $writefile $readfile |\
mail -s "$subject" $recipient -- -r "$sender"

sorry if you don't like the use of variables in explanations, but this seemed easiest.
$writefileis the filename as the person recieving the email will see it (can be same as $readfile)
$readfileis the filename as it is stored on your hard drive
$subjectis of course the subject of the mail you are sending
$recipientis the email address of the person you're sending it to
$senderis the email address that others will see in the From: field in their mail

uuencode should encode the file so that it will show as an attachment instead of just binary giberish or plain text, but for me, in thunderbird, this doesn't work.
the '|' of course means that you're using the left command as input for the right one
and mail is the mail command.

0 comments:

Post a Comment