I have an HTML file I am currently sending in the body of an email. I now have a need to send a csv attachment along with it. I can ONLY use sendmail as mutt and xmail etc are not on the server.
Here is what I am currently using: It is possible to add code to add an attachment ??!?
{
echo "From: $FROM"
echo "To: $MAILTO"
echo "Subject: Blah blah blah"
# echo "MIME-Version: 1.0"
# echo "Content-Type: text/html"
# echo "Content-Disposition: inline"
# cat myhtmlfile.html
#} | /usr/sbin/sendmail $MAILTO
My csv attachment sits in the same dir... e.g. myattachment.csv
##this will send three attachments
SUBJ="Send mail from Unix with file attachments"
TO=someone@domain_name
CC=someoneelse_1@domain_name,someoneelse_2@domain_name
(
cat << !
To : ${TO}
Subject : ${SUBJ}
Cc : ${CC}
!
cat << !
HOPE THIS WORKS
This sample E-mail message demonstrates how one can attach
files when sending messages with the Unix sendmail utility.
!
uuencode ${file_1} ${file_1}
uuencode ${file_2} ${file_2}
uuencode ${file_3} ${file_3}
!
) | sendmail -v ${TO} ${CC}
if still it is not working try this mailx :
(uuencode a.txt a.txt ; echo "this is body text " )| mailx -m -s a@yahoo.com
Thanks..... but the body of the email needs to be HTML and not txt.
SUBJ="Send mail from Unix with file attachments"
TO=someone@domain_name
CC=someoneelse_1@domain_name,someoneelse_2@domain_name
(
cat << !
To : ${TO}
Subject : ${SUBJ}
Cc : ${CC}
!
cat << !
##this is body message
##you may paste the html body in here or use the below if the html body exist in a file
`cat body.html`
!
uuencode ${file_1} ${file_1}
uuencode ${file_2} ${file_2}
uuencode ${file_3} ${file_3}
!
) | sendmail -v ${TO} ${CC}
Thanks... Will try this.. Correct me if im wrong though but will this not set the body of the text to the source html e.g. <html><header>This is html... etc etc ?
It should appear in new line.
Thanks for this..... but the HTML is displaying as text and not HTML... any idea ?
##this is body message
##you may paste the html body in here or use the below if the html body exist in a file
MIME-Version: 1.0
Content-Type: text/html
<table><td><b><u><font .................
BOUNDARY='=== This is the boundary between parts of the message. ==='
ADDRESS=whatever@whatever.com
ATTACHMENT=$FRAUD_DIR/reports/usageall.csv
BODY=$SPACE_MAIL
SUBJECT="whatever Report"
VERSION=1.0
print - "To: $TO <${ADDRESS}>"
if [[ -n $SUBJECT ]] ; then
print - 'Subject:' $SUBJECT
fi
print - 'MIME-Version: 1.0'
print - 'Content-Type: MULTIPART/MIXED; '
print - ' BOUNDARY='\"$BOUNDARY\"
print -
print - ' This message is in MIME format. But if you can see this,'
print - " you aren't using a MIME aware mail program. You shouldn't "
print - ' have too many problems because this message is entirely in'
print - ' ASCII and is designed to be somewhat readable with old '
print - ' mail software.'
print -
print - "--${BOUNDARY}"
print - 'Content-Type: TEXT/HTML; charset=US-ASCII'
print -
cat $BODY
print -
print -
print - "--${BOUNDARY}"
print - 'Content-Type: TEXT/PLAIN; charset=US-ASCII; name='${ATTACHMENT}
print - 'Content-Disposition: attachment; filename='whatever.csv
print -
cat ${ATTACHMENT}
print -
print - "--${BOUNDARY}--"
} | /usr/lib/sendmail $ADDRESS