How do you send an attachment with sendmail?
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.
Related videos on Youtube
Holly
I am a user who prefers to keep an air of mystery about myself, apparently.
Updated on September 18, 2022Comments
-
Holly over 1 year
How do you send an attachment with sendmail? I'm able to send an email with the below:
sendmail [email protected] < email.txt
I can't find out how to send one with an attachment, I've tried:
sendmail [email protected] < email.txt -a foo.pdf
-
Eduardo Lucio over 4 yearsRelated answer here: unix.stackexchange.com/a/507171/61742 .