Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3509
  • Last Modified:

email excel sheet as attachment using Sendmail

Experts,

Am having Sendmail installed on SunOS... Am able to attach and email Plain/Text file
But when i tried to attach & send Excel sheet using my script. am receiving excel sheet. when i download and open Ooops the file is in unrecognized format.....

I tried Content-type as application/vnd.excel
{
echo To: $EMAIL_TO
echo From: $EMAIL_FROM
echo Subject: $EMAIL_SUBJECT
echo 'MIME-Version: 1.0'
echo 'Content-type: multipart/mixed; boundary="***"'
echo '--***'
echo ''
echo $EMAIL_BODY
echo '--***'
echo 'Content-Disposition: attachment; filename="'$FILE_NAME'"'
echo ''
cat $ATTACHED_FILE
echo '--***'
} | /usr/sbin/sendmail -t $EMAIL_TO

Open in new window

0
sreehariharan
Asked:
sreehariharan
  • 10
  • 9
  • 2
  • +2
1 Solution
 
omarfaridCommented:
you run uuencode on the file, e.g.

uuencode myfile.xls < myfile.xls | sendmail username@domain
0
 
sreehariharanAuthor Commented:
Hi omarfarid,
Thanks for your Quick Reply... Here i need to specify From address also externally... will you please suggest me the step.


0
 
sreehariharanAuthor Commented:
Hi I tried your Solution also as

 uuencode myfile.xls < /home/user/src/myfile.xls | /usr/sbin/sendmail mymailid@gmail.com

but i received mail with junk letters
begin 644 myfile.xls
MT,\1X*&Q&N$`````````````````````.P`#`/[_"0`&```````````````!
M````````````````$```!0````$```#^____``````8```#_____________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M______________________]2`&\`;P!T`"``10!N`'0`<@!Y````````````
M````````````````````````````````````````````````%@`%`?______
M____`0````````````````````````````````````````````````````$`
M``#`!P```````%<`;P!R`&L`8@!O`&\`:P``````````````````````````
M```````````````````````````````````````2``(!________________
M`````````````````````````````````````````````````````+L'````
M````````````````````````````````````````````````````````````
M``````````````````````````````(```#_______________\`````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````@```/_______________P``````````````````
M``````````````````````````````````````````````D($```!@4`TQ#,
M!T$````&````X0`"`+`$P0`"````X@```%P`<``$``!C;&%R:69Y("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@0@`"`+`$80$"````/0$$`````0"<``(`#@`9``(````2``(````3
M``(```"O`0(```"\`0(````]`!(`:`$.`5PZOB,X```````!`%@"0``"````
MC0`"````(@`"````#@`"``$`MP$"````V@`"````,0`:`,@```#_?Y`!````
M````!0%!`'(`:0!A`&P`,0`:`,@```#_?Y`!````````!0%!`'(`:0!A`&P`
M,0`:`,@```#_?Y`!````````!0%!`'(`:0!A`&P`,0`:`,@```#_?Y`!````
M````!0%!`'(`:0!A`&P`'@0<``4`%P``(B0B(RPC(S!?*3M<*"(D(B,L(R,P
M7"D>!"$`!@`<```B)"(C+",C,%\I.UM2961=7"@B)"(C+",C,%PI'@0B``<`
M'0``(B0B(RPC(S`N,#!?*3M<*"(D(B,L(R,P+C`P7"D>!"<`"``B```B)"(C
M+",C,"XP,%\I.UM2961=7"@B)"(C+",C,"XP,%PI'@0W`"H`,@``7R@B)"(J
M(",L(R,P7RD[7R@B)"(J(%PH(RPC(S!<*3M?*"(D(BH@(BTB7RD[7RA`7RD>
M!"X`*0`I``!?*"H@(RPC(S!?*3M?*"H@7"@C+",C,%PI.U\H*B`B+2)?*3M?
M*$!?*1X$/P`L`#H``%\H(B0B*B`C+",C,"XP,%\I.U\H(B0B*B!<*",L(R,P
M+C`P7"D[7R@B)"(J("(M(C\_7RD[7RA`7RD>!#8`*P`Q``!?*"H@(RPC(S`N
M,#!?*3M?*"H@7"@C+",C,"XP,%PI.U\H*B`B+2(_/U\I.U\H0%\IX``4````
M``#U_R```````````````,`@X``4``$```#U_R```/0``````````,`@X``4
M``$```#U_R```/0``````````,`@X``4``(```#U_R```/0``````````,`@
MX``4``(```#U_R```/0``````````,`@X``4``````#U_R```/0`````````
M`,`@X``4``````#U_R```/0``````````,`@X``4``````#U_R```/0`````
M`````,`@X``4``````#U_R```/0``````````,`@X``4``````#U_R```/0`
M`````````,`@X``4``````#U_R```/0``````````,`@X``4``````#U_R``
M`/0``````````,`@X``4``````#U_R```/0``````````,`@X``4``````#U
M_R```/0``````````,`@X``4``````#U_R```/0``````````,`@X``4````
M```!`"```````````````,`@X``4``$`*P#U_R```/@``````````,`@X``4
M``$`*0#U_R```/@``````````,`@X``4``$`+`#U_R```/@``````````,`@
MX``4``$`*@#U_R```/@``````````,`@X``4``$`"0#U_R```/@`````````
M`,`@DP($`!"``_^3`@0`$8`&_Y,"!``2@`3_DP($`!.`!_^3`@0``(``_Y,"
M!``4@`7_8`$"````A0`3`)4%``````L`9FER<W0@<VAE972%`!0`P`8`````
M#`!S96-O;F0@<VAE972,``0``0`!`/P`&``"`````@````4``$UA;F]J!0``
M2W5M87+_``H`"`!S!0``#`````H````)"!````80`+L-S`?!````!@````T`
M`@`!``P``@!D``\``@`!`!$``@```!``"`#\J?'236)0/U\``@`!`"H``@``
M`"L``@```((``@`!`(``"````````````"4"!````/\`@0`"`,$$&P`"````
M&@`"````%````!4```"#``(```"$``(```"A`"(``0!D``$``0`!``(`+`$L
M`0```````.`_````````X#\``%4``@`(```"#@```````0```````0```/T`
M"@``````#P``````_0`*`````0`/``$````(`A````````$`_P````````$`
M`#X"$@"V!@````!````````````````=``\``P````````$`````````$@`"
M````"@````D($```!A``NPW,!\$````&````#0`"``$`#``"`&0`#P`"``$`
M$0`"````$``(`/RI\=)-8E`_7P`"``$`*@`"````*P`"````@@`"``$`@``(
M````````````)0($````_P"!``(`P00;``(````:``(````4````%0```(,`
M`@```(0``@```*$`(@`!`&0``0`!``$``@`L`2P!````````X#\```````#@
M/P``50`"``@```(.```````!```````!````/@(2`+8``````$``````````
M`````!T`#P`#`````````0`````````2``(````*````________________
M____________________________________________________________
M________________`0````(````#````!`````4````&````!P````@````)
M````"@````L````,````#0````X````/````$````!$````2````$P```!0`
M```5````%@```!<````8````&0```!H````;````'````!T````>````_O__
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M_______________________________________^____`@````,````$````
M_O____[____^________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
!____
`

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
omarfaridCommented:
try this

uuencode myfile.xls myfile.xls | mailx -s "subject" user@domain.com
0
 
sreehariharanAuthor Commented:
I Tried and tired on searching with this....
This also showing some junk mails....
begin 775 workbook.xls
MT,\1X*&Q&N$`````````````````````.P`#`/[_"0`&```````````````!
M````````````````$```!0````$```#^____``````8```#_____________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M______________________]2`&\`;P!T`"``10!N`'0`<@!Y````````````
M````````````````````````````````````````````````%@`%`?______
M____`0````````````````````````````````````````````````````$`
M``#`!P```````%<`;P!R`&L`8@!O`&\`:P``````````````````````````
M```````````````````````````````````````2``(!________________
M`````````````````````````````````````````````````````+L'````
M````````````````````````````````````````````````````````````
M``````````````````````````````(```#_______________\`````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````@```/_______________P``````````````````
M``````````````````````````````````````````````D($```!@4`TQ#,
M!T$````&````X0`"`+`$P0`"````X@```%P`<``$``!C;&%R:69Y("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@
M("`@("`@0@`"`+`$80$"````/0$$`````0"<``(`#@`9``(````2``(````3
M``(```"O`0(```"\`0(````]`!(`:`$.`5PZOB,X```````!`%@"0``"````
MC0`"````(@`"````#@`"``$`MP$"````V@`"````,0`:`,@```#_?Y`!````
M````!0%!`'(`:0!A`&P`,0`:`,@```#_?Y`!````````!0%!`'(`:0!A`&P`
M,0`:`,@```#_?Y`!````````!0%!`'(`:0!A`&P`,0`:`,@```#_?Y`!````
M````!0%!`'(`:0!A`&P`'@0<``4`%P``(B0B(RPC(S!?*3M<*"(D(B,L(R,P
M7"D>!"$`!@`<```B)"(C+",C,%\I.UM2961=7"@B)"(C+",C,%PI'@0B``<`
M'0``(B0B(RPC(S`N,#!?*3M<*"(D(B,L(R,P+C`P7"D>!"<`"``B```B)"(C
M+",C,"XP,%\I.UM2961=7"@B)"(C+",C,"XP,%PI'@0W`"H`,@``7R@B)"(J
M(",L(R,P7RD[7R@B)"(J(%PH(RPC(S!<*3M?*"(D(BH@(BTB7RD[7RA`7RD>
M!"X`*0`I``!?*"H@(RPC(S!?*3M?*"H@7"@C+",C,%PI.U\H*B`B+2)?*3M?
M*$!?*1X$/P`L`#H``%\H(B0B*B`C+",C,"XP,%\I.U\H(B0B*B!<*",L(R,P
M+C`P7"D[7R@B)"(J("(M(C\_7RD[7RA`7RD>!#8`*P`Q``!?*"H@(RPC(S`N
M,#!?*3M?*"H@7"@C+",C,"XP,%PI.U\H*B`B+2(_/U\I.U\H0%\IX``4````
M``#U_R```````````````,`@X``4``$```#U_R```/0``````````,`@X``4
M``$```#U_R```/0``````````,`@X``4``(```#U_R```/0``````````,`@
MX``4``(```#U_R```/0``````````,`@X``4``````#U_R```/0`````````
M`,`@X``4``````#U_R```/0``````````,`@X``4``````#U_R```/0`````
M`````,`@X``4``````#U_R```/0``````````,`@X``4``````#U_R```/0`
M`````````,`@X``4``````#U_R```/0``````````,`@X``4``````#U_R``
M`/0``````````,`@X``4``````#U_R```/0``````````,`@X``4``````#U
M_R```/0``````````,`@X``4``````#U_R```/0``````````,`@X``4````
M```!`"```````````````,`@X``4``$`*P#U_R```/@``````````,`@X``4
M``$`*0#U_R```/@``````````,`@X``4``$`+`#U_R```/@``````````,`@
MX``4``$`*@#U_R```/@``````````,`@X``4``$`"0#U_R```/@`````````
M`,`@DP($`!"``_^3`@0`$8`&_Y,"!``2@`3_DP($`!.`!_^3`@0``(``_Y,"
M!``4@`7_8`$"````A0`3`)4%``````L`9FER<W0@<VAE972%`!0`P`8`````
M#`!S96-O;F0@<VAE972,``0``0`!`/P`&``"`````@````4``$UA;F]J!0``
M2W5M87+_``H`"`!S!0``#`````H````)"!````80`+L-S`?!````!@````T`
M`@`!``P``@!D``\``@`!`!$``@```!``"`#\J?'236)0/U\``@`!`"H``@``
M`"L``@```((``@`!`(``"````````````"4"!````/\`@0`"`,$$&P`"````
M&@`"````%````!4```"#``(```"$``(```"A`"(``0!D``$``0`!``(`+`$L
M`0```````.`_````````X#\``%4``@`(```"#@```````0```````0```/T`
M"@``````#P``````_0`*`````0`/``$````(`A````````$`_P````````$`
M`#X"$@"V!@````!````````````````=``\``P````````$`````````$@`"
M````"@````D($```!A``NPW,!\$````&````#0`"``$`#``"`&0`#P`"``$`
M$0`"````$``(`/RI\=)-8E`_7P`"``$`*@`"````*P`"````@@`"``$`@``(
M````````````)0($````_P"!``(`P00;``(````:``(````4````%0```(,`
M`@```(0``@```*$`(@`!`&0``0`!``$``@`L`2P!````````X#\```````#@
M/P``50`"``@```(.```````!```````!````/@(2`+8``````$``````````
M`````!T`#P`#`````````0`````````2``(````*````________________
M____________________________________________________________
M________________`0````(````#````!`````4````&````!P````@````)
M````"@````L````,````#0````X````/````$````!$````2````$P```!0`
M```5````%@```!<````8````&0```!H````;````'````!T````>````_O__
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M_______________________________________^____`@````,````$````
M_O____[____^________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
M____________________________________________________________
!____
`
end

Open in new window

0
 
Maciej SsysadminCommented:
Can you use mutt/mail/mailx instead of sendmail?
0
 
Maciej SsysadminCommented:
Oh, I see that omarfarid already wrote about mailx. mutt would be the easiest way :)
echo "body of email" | mutt -x -a file.to.attach user@domain
0
 
omarfaridCommented:
oklit:

Please feel free to repeat the same recommendation since it might strength the proposed one.
0
 
sreehariharanAuthor Commented:
Oklit,
  Thanks for ur response and omarfarid thanks for ur support...

I tried with mutt, but it was not configured in my server.
am getting following error



ksh: mutt:  not found

Open in new window

0
 
omarfaridCommented:
you may download and install from sunfreeware.com:\

http://sunfreeware.com/programlistsparc10.html#mutt
ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/mutt-1.5.18-sol10-sparc-local.gz

The provided links are for solaris 10. Please note that you may need to install additional s/w, please see dependencies in the provided link.

Once downloaded, run

gunzip mutt-1.5.18-sol10-sparc-local.gz
pkgadd -d mutt-1.5.18-sol10-sparc-local
0
 
sreehariharanAuthor Commented:
Omar... But this to be on our server Machines and we dont have access to install any softwares...
do we cant send with sendmail itself by changing the option of Content-Type Encoding such things ?...
0
 
omarfaridCommented:
What client do you use to read received messages? mail clients like mail and mailx can not deal with attachments.
0
 
sreehariharanAuthor Commented:
We are not having any mail Clients.. This is the SunOS box with CLI and not a GUI. Its having Sendmail software to send mails... and not having any clients to read... Since this server machine is used to send mail only and not intend of receiving mails....
0
 
omarfaridCommented:
in your previous posts you showed that you are getting text and no attachments. From where you were reading this email?
0
 
sreehariharanAuthor Commented:
am sending it to my Gmail ID and from there am reading my mails and posting...
0
 
omarfaridCommented:
how the excel sheet is uploaded to solaris server? are you using ftp to upload?
0
 
sreehariharanAuthor Commented:
yes i ftped in binary mode...

Here i made some modification to my code
Please see the code Snippet...
am using encoding technique as X-UUencode
am able to receive my proper excel sheet in my IBM Lotus Mail Client, but not with gmail...
when i opened with gmail its showing some junk charecters...
i found that gmails and most of the mail-exchanges are using base64 type encoding....
do you know how to convert our files from binary to base64?...


#!/usr/bin/sh
 
export EMAIL_FROM=$1
export EMAIL_TO=$2
export EMAIL_SUBJECT=$3
export EMAIL_BODY=$4
export FILE_NAME=$5
export ATTACHED_FILE=$6
 
{
echo To: $EMAIL_TO
echo From: $EMAIL_FROM
echo Subject: $EMAIL_SUBJECT
echo 'MIME-Version: 1.0'
echo 'Content-type: multipart/mixed; boundary="***"'
echo ''
echo '--***'
echo 'Content-type: text/plain; charset=ISO-8859-1'
echo 'Content-Transfer-Encoding: quoted-printable'
echo ''
echo $EMAIL_BODY
echo '--***'
echo 'Content-Type: application/vnd.ms-excel; name="'$FILE_NAME'"'
echo 'Content-Transfer-Encoding: X-uuencode'
echo 'Content-Disposition: attachment; filename="'$FILE_NAME'"'
echo ''
uuencode $ATTACHED_FILE $ATTACHED_FILE
echo '--***'
} | /usr/sbin/sendmail -t $EMAIL_TO
 
echo "Mail Sent"

Open in new window

0
 
omarfaridCommented:
uuencode has th -m option which according to man page:

"  -m              Encodes source-file  using  Base64  encoding and sends it to standard output."

I used it and sent file to gmail and faced same problem. hotmail rejected my message and could not verify, however I tried it with some other mail system and it was received properly.
0
 
sreehariharanAuthor Commented:
Ya same issue for me too... But my OS is HP-UX, i wrongly mentioned as SunOS...
in HP-UX it doesnt have -m option... :(
0
 
sreehariharanAuthor Commented:
I Checked with the same on hotmail and also on Yahoo too...
i received the same error... its not decrypting my excel sheet properly...
0
 
anand_2000vCommented:
send mail will not work. try

uuencode myfile.xls myfile.xls | mailx -s <Subject u wish to give >  username@domain

if mailx is not working , use mail command
0
 
sagar2788Commented:
above command is not working  do we have any other option for this ?
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 10
  • 9
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now