How do you send an attachment with sendmail? I'm able to send an email with the below:

sendmail johndoe@example.com < email.txt 

I can't find out how to send one with an attachment, I've tried:

sendmail johndoe@example.com < email.txt -a foo.pdf

3 Answers 3


That's not how sendmail works. It just deals with transporting the mail and expects a properly encoded mail already.

You could do this encoding yourself or just use mail/mailx/mutt instead to hand over a suitable mail over to sendmail for delivery.


You can use uuencode to encode the attachment.
Most email clients recognize uuencoded attachments.

Make sure there is an empty line after email headers in email.txt file. Sendmail expects "raw" message.

(cat email.txt; uuencode foo.pdf foo.pdf)|/usr/sbin/sendmail -i -- johndow@example.com 

You really shouldn't call sendmail directly but use mail or mailx which will also help you set up the correct headers and such. Moderns version of those support adding attachments with the -a option.

The alternative, is to MIME (base645) encode your attachment and include it, with the correct headers in the body of your raw email text and submit that to sendmail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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