Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've just setup a new Ubuntu 10.04 LTS server on linode for myself. Followed an excellent instruction at: here to finish the installation of some basic stuff including postfix.

I am trying to figure out a way to send an email to my gmail address with an attachment, but cannot find how. Already confirmed that email can reach my gmail account.

In the end I have to use mutt to send the email with attachments, probably SendEmails will also do well, but I am wondering how to do the same thing in postfix from command-line?

Many thanks in advance for this dumb question.

share|improve this question
up vote 14 down vote accepted

Why does it have to be postfix directly? mailx -a, mutt, or mutt -a will also use the sendmail interface -- unless you configure them for SMTP.

echo "This is a test message" | mutt -s Test -a -- $USER
echo "This is a test message" | mail -s Test -a $USER

(Note, in bsd-mailx the option is -A instead.)

Anyway, here's a "postfix" example.

Replace $USER, content type and filename to match your environment. Example assumes you are sending the message to yourself and have a ZIP file in the current directory.

(printf "%s\n" \
    "Subject: test" \
    "To: $USER" \
    "Content-Type: application/zip" \
    "Content-Disposition: attachment;" \
    "Content-Transfer-Encoding: base64" \
 base64 | sendmail "$USER"

(Creation of MIME multipart messages left as an exercise to the reader.)

share|improve this answer
mail -a does not attach to a message as with mutt. – n.r. Jun 10 '13 at 14:54
@nicolai.rostov: depends on mail, I guess. It does so in heirloom-mailx. – grawity Jul 21 '13 at 13:33

Postfix is a mail transfer agent (MTA). Its job is to handle the delivery of the mail: pick it up and send it to the next point on its route. Postfix is a postal worker, whose job is to take an envelope and (with help from its colleagues) carry it to the recipient.

What you're asking for here is secretarial work: assembling documents to put them in the envelope. That's not Postfix's job: it's a job for a mail user agent (MUA). You can write a crude MUA that just assembles pieces to make a mail in a few lines of shell, as grawity did, but Mutt is really a good tool for this task.

share|improve this answer

From the command line, I like to use "sendemail", which on ubuntu / debian can be installed from the command line like so:

apt-get install sendemail

Then you can simply tell it to use localhost (Postfix) as the MTA.

Actually I just noticed that localhost:25 is the default:

-s SERVER[:PORT]          smtp mail relay, default is localhost:25

You then add attachments using the -a flag:

sendemail -f -t -m "This is the message" -u "This is the subject" -a
share|improve this answer

mailx 12.4 has an option for attaching files:

-a file
    Attach the given file to the message.

For example:

[gawad@centos Desktop]$ mail -s "pine" -a pine.rpm.gz root@localhostEnter
this is the pine software you asked forEnter
[gawad@centos Desktop]$ 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.