Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 09-22-2004, 02:54 AM   #1
LQ Newbie
Registered: Nov 2003
Posts: 2

Rep: Reputation: 0
Cool 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
export mailto
/usr/lib/sendmail -f -v $mailto <<EOF
Subject: Test.
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="==Porsche====================="

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

Some text message

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

`cat $1`

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/; 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.

Old 09-22-2004, 06:48 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
`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.
Old 09-23-2004, 01:59 AM   #3
LQ Newbie
Registered: Nov 2003
Posts: 2

Original Poster
Rep: Reputation: 0

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.
Old 09-24-2004, 02:29 PM   #4
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cmd line send attachment? jedimastermopar Linux - General 2 06-16-2005 01:51 PM
send mails with attachment ProXXXy Linux - Networking 2 08-18-2004 04:33 AM
Attachment size in Sendmail RajaRC Linux - General 6 03-23-2004 12:05 AM
howto send a mail with attachment via perl script ? cccc Programming 24 03-05-2004 08:49 PM
Send Email + Txt Attachment Using Cron Job beringer Linux - Newbie 3 01-31-2003 11:23 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration