Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

4 Answers

up vote 12 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 foo.zip -- $USER
echo "This is a test message" | mail -s Test -a foo.zip $USER

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 foo.zip in the current directory.

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

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

share|improve this answer
    
mail -a foo.zip does not attach foo.zip to a message as with mutt. –  nicolai.rostov 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
add comment

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
add comment

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 sender@example.com -t recipient@example.com -m "This is the message" -u "This is the subject" -a file1.zip file2.zip
share|improve this answer
add comment

this is how it worked for me:

[gawad@centos Desktop]$ mail -s "pine"  -a /home/gawad/Desktop/pine-4.64-3.el5.rf.x86_64.rpm.gz root@localhost   *press enter and add the mail body*
this is the pine software you asked for
.    *press enter*
EOT
[gawad@centos Desktop]$ 
share|improve this answer
add comment

Your Answer

 
discard

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.