Help with attachment in sendmail

Hi Folks

I have below code, which is able to successfully send the content of the output file as html which is body, but i did tried uuencode & mailx -a for sending attachments but to no avail.

cat - ${Output_File} <<EOF| /usr/sbin/sendmail -oi -t
#From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
#mailx -s $SUBJECT  -a pe_report.csv $MAILTO
EOF

[/CODE]

Can you please help me in modifying the above code so that i can send even the attachment along with it.

Don't use uuencode, here is an example using base64 and sendmail

2 Likes

uuencode is so old many modern mail clients have stopped supporting it.

Hi Yoda,

I just referred the code shared in the link and i did changes accordingly which i'm assuming but i'm not still getting the attachment and this time even the html format took a hit in the mail it was trash.

Below is the changed code, please let me know what wrong have i done?

cat - ${Output_File} <<EOF| /usr/sbin/sendmail -oi -t
#From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Content-Type: text/plain; name=pe_report.csv
        Content-Transfer-Encoding: base64
        Content-Disposition: attachment; filename=pe_report.csv
        base64 /home/local/ANT//pe_report.csv
#mailx -s $SUBJECT  -a pe_report.csv $MAILTO
EOF

[/CODE]

the blank lines are inportant

Hi Yoda,

I did used the code again you shared in the link with no modifications except for the file names and file paths, It worked swiftly.

Thanks a lot.