Can sendmail include an attachment?

Is it possible to include an attachment with sendmail? I am generating the following emailfile.eml files with the following layout

From: Company Name <<a href="" class="__cf_email__" data-cfemail="4b26322824263b2a25320b2e332a263b272e65282426">[email protected]</a>>
To: <a href="" class="__cf_email__" data-cfemail="483a2d2b2138212d263c082d30292538242d662b2725">[email protected]</a>
CC: <a href="" class="__cf_email__" data-cfemail="44372b29212b2a212128372104213c25293428216a272b29">[email protected]</a>
Subject: Generated Output

Mime-Version: 1.0

This will be the body copy even though it's terrible

I am sending these emails using
# /usr/sbin/sendmail -t < emailfile.eml

This part is working file but I would like to include an attachment to this email.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

With mutt you can simply use:

echo "This is the message body" | mutt -a "/path/to/file_to_attach" -s "subject of message" -- <a href="" class="__cf_email__" data-cfemail="285a4d4b4158414d465c684c4745494146064b4745">[email protected]</a>

Using mail command:
mail -a /opt/emailfile.eml -s "Email File" <a href="" class="__cf_email__" data-cfemail="ee9b9d8b9cae8b968f839e828bc08d8183">[email protected]</a> < /dev/null

-a is used for attachments.

You can use SendEmail:

sendemail -t <a href="" class="__cf_email__" data-cfemail="b0c4dff0d5c8d1ddc0dcd59ed3dfdd">[email protected]</a> -m "Here is the file." -a attachmentFile

Method 2

Posting the solution that worked for me in case it can help anyone else, sorry it’s so late.

The most reliable way I found for doing this was to include the attachment as base64 in the eml file itself, bellow is an example of the eml contents.

Note 01 : the base64 for the file comes from running the base64 command on linux using the attachment as an argument (should work with any base64 tool)

Note 02 : the string used for the boundary is just nonsense using the date and random upper case letters

Filename : emlfile.eml

From: Sender <<a href="" class="__cf_email__" data-cfemail="d4a7b1bab0b1a694b1b9b5bdb8fab7bbfaaeb5">[email protected]</a>>
To: <a href="" class="__cf_email__" data-cfemail="e29087818b928b878c96d2d3a2878f838b8ecc818dcc9883">[email protected]</a>
CC: <a href="" class="__cf_email__" data-cfemail="61130402081108040f15515321040c00080d4f020e4f1b00">[email protected]</a>
Disposition-Notification-To: <a href="" class="__cf_email__" data-cfemail="a0d2c5c3c9d0c9c5ced49091e0c5cdc1c9cc8ec3cf8edac1">[email protected]</a>
Subject: Generic Subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="19032019ABCDE"

Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Generic Body Copy

Content-Type: application;
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="MyPdfAttachment.pdf"

*base64 string goes here (no asterix)*


Then the filename.eml file can be sent using the command and it will include the attachment
# /usr/sbin/sendmail -t < filename.eml

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments