How do you send an attachment with sendmail?

16,985

Solution 1

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.

Solution 2

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.

#!/bin/sh
(cat email.txt; uuencode foo.pdf foo.pdf)|/usr/sbin/sendmail -i -- [email protected] 

Solution 3

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.

Share:
16,985

Related videos on Youtube

Holly
Author by

Holly

I am a user who prefers to keep an air of mystery about myself, apparently.

Updated on September 18, 2022

Comments