LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Send excel attachment using sendmail (https://www.linuxquestions.org/questions/linux-software-2/send-excel-attachment-using-sendmail-233688/)

cwseetoh 09-22-2004 01:54 AM

Send excel attachment using sendmail
 
I'm using linux redhat 7. Currently I have a shell program that will send an email with an attachment, below are the codes:

echo $1
echo $2
mailto=$2
export mailto
/usr/lib/sendmail -f user@server.com -v $mailto <<EOF
To:$mailto
Cc:
Subject: Test.
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="==Porsche====================="

--==Porsche=====================
Content-Type: text/plain; charset="us-ascii"

Some text message

--==Porsche=====================
Content-Type: application/octet-stream; name="${1##*/}"
Content-Transfer-Encoding: binary
Content-Disposition: attachment; filename="${1##*/}"

`cat $1`
--==Porsche=====================--
EOF

Using the above code, I can send an email with some text and a text file attachment. Now that I want to send an excel file attachment, I made the following changes:

1) Content-Type: application/vnd.ms-excel; name="${1##*/}"
2) Content-Transfer-Encoding: base64

However this doesn't work. The actual file received is an invalid excel file. Anybody can help me on this? Thanks.

Regards,
Alfred

rjlee 09-22-2004 05:48 AM

`cat $1`

You need to Base64-encode the file if you set the transfer-encoding to Base64. You were right with binary encoding if you're just dumping the file inline.

But it's better to use base-64 because this will cope with problems caused by non-8-bit clean gateways and odd things being in the file. Try googling for a base-64 encoding program, install it and use it in place of cat.

cwseetoh 09-23-2004 12:59 AM

Hi rjlee, thanks for your prompt help.

First of all, I tried changing the following

1) Content-Transfer-Encoding: binary
2) Content-Disposition: inline; filename="${1##*/}"

However this also doesn't seem to work.

Secondly, you mention about using the base64 encoder. If let's say I use it, then does that mean the recipient needs to manually decode it before able to open the excel file. Sorry, I'm not very familiar with all these stuff.

rjlee 09-24-2004 01:29 PM

No. If you set Base64 encoding in the headers, then all modern email clients will decode it for you.

The purpose of base-64 encoding is to circumvent most of the limitations in the SMTP protocol (specifically, the original standard required all characters to be 7-bit ASCII, the line length was/is limited, and it gave/gives special meaning to certain combinations of characters, like a dot at the start of the line meaning “end of message”). By encoding your attachment as Base-64, it has the best chance of actually getting to the recipient.


All times are GMT -5. The time now is 03:11 PM.