Send mail with an attachment and body of mail with table format

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I need to send a mail with an attachment and body of mail in table format.I have used the below code to send mail. but unable to attache file.



 (echo "From: "; 
echo "Subject: testing of table using awk";
echo "Content-type: text/html";
echo;
awk 'BEGINprint "<table>" print "<tr><tr>";for(i=1;i<=NF;i++)print "<td><td>" $i"</td></td>";print "</tr></tr>" ENDprint "</table>"' input1.txt;
) | sendmail xxx@yyy.com






share|improve this question


























    up vote
    2
    down vote

    favorite












    I need to send a mail with an attachment and body of mail in table format.I have used the below code to send mail. but unable to attache file.



     (echo "From: "; 
    echo "Subject: testing of table using awk";
    echo "Content-type: text/html";
    echo;
    awk 'BEGINprint "<table>" print "<tr><tr>";for(i=1;i<=NF;i++)print "<td><td>" $i"</td></td>";print "</tr></tr>" ENDprint "</table>"' input1.txt;
    ) | sendmail xxx@yyy.com






    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I need to send a mail with an attachment and body of mail in table format.I have used the below code to send mail. but unable to attache file.



       (echo "From: "; 
      echo "Subject: testing of table using awk";
      echo "Content-type: text/html";
      echo;
      awk 'BEGINprint "<table>" print "<tr><tr>";for(i=1;i<=NF;i++)print "<td><td>" $i"</td></td>";print "</tr></tr>" ENDprint "</table>"' input1.txt;
      ) | sendmail xxx@yyy.com






      share|improve this question














      I need to send a mail with an attachment and body of mail in table format.I have used the below code to send mail. but unable to attache file.



       (echo "From: "; 
      echo "Subject: testing of table using awk";
      echo "Content-type: text/html";
      echo;
      awk 'BEGINprint "<table>" print "<tr><tr>";for(i=1;i<=NF;i++)print "<td><td>" $i"</td></td>";print "</tr></tr>" ENDprint "</table>"' input1.txt;
      ) | sendmail xxx@yyy.com








      share|improve this question













      share|improve this question




      share|improve this question








      edited May 16 at 19:21

























      asked Mar 7 at 17:14









      SivaPrasath

      6,23143255




      6,23143255




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          Try to use a version of mail command supporting -a (attachment) switch . It's the more reliable solution.



          s-nail have it !



          email=foo@base

          mail -v -s subject foo@bar -a file.txt -q - <<EOF
          $(awk '
          BEGINprint "<table>"

          print "<tr><tr>";
          for(i=1;i<=NF;i++)
          print "<td><td>" $i"</td></td>";
          print "</tr></tr>";


          ENDprint "</table>"' input1.txt
          )

          .
          EOF


          Check man mail if you need to add headers and such






          share|improve this answer






















          • i need body of mail with table format as well...
            – SivaPrasath
            Mar 7 at 17:44










          • mail command is not converting to table format. it is printing with html tags..
            – SivaPrasath
            Mar 7 at 17:56










          • Sure, you need to read the man mail to add headers as already said
            – Gilles Quenot
            Mar 7 at 18:26

















          up vote
          0
          down vote



          accepted










          Using sendmail:



          TO_ADDRESS="abc@example.com"
          SUBJECT="Test Mail"

          cat << --OEF--
          Subject: $SUBJECT
          TO: $TO_ADDRESS
          MIME-Version: 1.0
          Content-Type: multipart/mixed;
          boundary="MAIL_BOUNDARY"


          --MAIL_BOUNDARY
          Content-Type: multipart/alternative;
          boundary="MAIL_BOUNDARY2"

          --MAIL_BOUNDARY2
          Content-Type: text/plain; charset=utf-8

          $SUBJECT

          --MAIL_BOUNDARY2
          Content-Type: text/html; charset=utf-8

          --OEF--
          cat MailBody.html

          cat << --OEF--

          --MAIL_BOUNDARY2--

          --MAIL_BOUNDARY
          Content-Type: application/zip; name=file.zip
          Content-Disposition: attachment; filename=file.zip
          Content-Transfer-Encoding: base64

          --OEF--
          base64 /opt/file.zip
          cat << --OEF--

          --MAIL_BOUNDARY--
          --OEF--
          ) | /usr/sbin/sendmail $TO_ADDRESS





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428805%2fsend-mail-with-an-attachment-and-body-of-mail-with-table-format%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            Try to use a version of mail command supporting -a (attachment) switch . It's the more reliable solution.



            s-nail have it !



            email=foo@base

            mail -v -s subject foo@bar -a file.txt -q - <<EOF
            $(awk '
            BEGINprint "<table>"

            print "<tr><tr>";
            for(i=1;i<=NF;i++)
            print "<td><td>" $i"</td></td>";
            print "</tr></tr>";


            ENDprint "</table>"' input1.txt
            )

            .
            EOF


            Check man mail if you need to add headers and such






            share|improve this answer






















            • i need body of mail with table format as well...
              – SivaPrasath
              Mar 7 at 17:44










            • mail command is not converting to table format. it is printing with html tags..
              – SivaPrasath
              Mar 7 at 17:56










            • Sure, you need to read the man mail to add headers as already said
              – Gilles Quenot
              Mar 7 at 18:26














            up vote
            2
            down vote













            Try to use a version of mail command supporting -a (attachment) switch . It's the more reliable solution.



            s-nail have it !



            email=foo@base

            mail -v -s subject foo@bar -a file.txt -q - <<EOF
            $(awk '
            BEGINprint "<table>"

            print "<tr><tr>";
            for(i=1;i<=NF;i++)
            print "<td><td>" $i"</td></td>";
            print "</tr></tr>";


            ENDprint "</table>"' input1.txt
            )

            .
            EOF


            Check man mail if you need to add headers and such






            share|improve this answer






















            • i need body of mail with table format as well...
              – SivaPrasath
              Mar 7 at 17:44










            • mail command is not converting to table format. it is printing with html tags..
              – SivaPrasath
              Mar 7 at 17:56










            • Sure, you need to read the man mail to add headers as already said
              – Gilles Quenot
              Mar 7 at 18:26












            up vote
            2
            down vote










            up vote
            2
            down vote









            Try to use a version of mail command supporting -a (attachment) switch . It's the more reliable solution.



            s-nail have it !



            email=foo@base

            mail -v -s subject foo@bar -a file.txt -q - <<EOF
            $(awk '
            BEGINprint "<table>"

            print "<tr><tr>";
            for(i=1;i<=NF;i++)
            print "<td><td>" $i"</td></td>";
            print "</tr></tr>";


            ENDprint "</table>"' input1.txt
            )

            .
            EOF


            Check man mail if you need to add headers and such






            share|improve this answer














            Try to use a version of mail command supporting -a (attachment) switch . It's the more reliable solution.



            s-nail have it !



            email=foo@base

            mail -v -s subject foo@bar -a file.txt -q - <<EOF
            $(awk '
            BEGINprint "<table>"

            print "<tr><tr>";
            for(i=1;i<=NF;i++)
            print "<td><td>" $i"</td></td>";
            print "</tr></tr>";


            ENDprint "</table>"' input1.txt
            )

            .
            EOF


            Check man mail if you need to add headers and such







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 7 at 18:27

























            answered Mar 7 at 17:21









            Gilles Quenot

            15.3k13448




            15.3k13448











            • i need body of mail with table format as well...
              – SivaPrasath
              Mar 7 at 17:44










            • mail command is not converting to table format. it is printing with html tags..
              – SivaPrasath
              Mar 7 at 17:56










            • Sure, you need to read the man mail to add headers as already said
              – Gilles Quenot
              Mar 7 at 18:26
















            • i need body of mail with table format as well...
              – SivaPrasath
              Mar 7 at 17:44










            • mail command is not converting to table format. it is printing with html tags..
              – SivaPrasath
              Mar 7 at 17:56










            • Sure, you need to read the man mail to add headers as already said
              – Gilles Quenot
              Mar 7 at 18:26















            i need body of mail with table format as well...
            – SivaPrasath
            Mar 7 at 17:44




            i need body of mail with table format as well...
            – SivaPrasath
            Mar 7 at 17:44












            mail command is not converting to table format. it is printing with html tags..
            – SivaPrasath
            Mar 7 at 17:56




            mail command is not converting to table format. it is printing with html tags..
            – SivaPrasath
            Mar 7 at 17:56












            Sure, you need to read the man mail to add headers as already said
            – Gilles Quenot
            Mar 7 at 18:26




            Sure, you need to read the man mail to add headers as already said
            – Gilles Quenot
            Mar 7 at 18:26












            up vote
            0
            down vote



            accepted










            Using sendmail:



            TO_ADDRESS="abc@example.com"
            SUBJECT="Test Mail"

            cat << --OEF--
            Subject: $SUBJECT
            TO: $TO_ADDRESS
            MIME-Version: 1.0
            Content-Type: multipart/mixed;
            boundary="MAIL_BOUNDARY"


            --MAIL_BOUNDARY
            Content-Type: multipart/alternative;
            boundary="MAIL_BOUNDARY2"

            --MAIL_BOUNDARY2
            Content-Type: text/plain; charset=utf-8

            $SUBJECT

            --MAIL_BOUNDARY2
            Content-Type: text/html; charset=utf-8

            --OEF--
            cat MailBody.html

            cat << --OEF--

            --MAIL_BOUNDARY2--

            --MAIL_BOUNDARY
            Content-Type: application/zip; name=file.zip
            Content-Disposition: attachment; filename=file.zip
            Content-Transfer-Encoding: base64

            --OEF--
            base64 /opt/file.zip
            cat << --OEF--

            --MAIL_BOUNDARY--
            --OEF--
            ) | /usr/sbin/sendmail $TO_ADDRESS





            share|improve this answer
























              up vote
              0
              down vote



              accepted










              Using sendmail:



              TO_ADDRESS="abc@example.com"
              SUBJECT="Test Mail"

              cat << --OEF--
              Subject: $SUBJECT
              TO: $TO_ADDRESS
              MIME-Version: 1.0
              Content-Type: multipart/mixed;
              boundary="MAIL_BOUNDARY"


              --MAIL_BOUNDARY
              Content-Type: multipart/alternative;
              boundary="MAIL_BOUNDARY2"

              --MAIL_BOUNDARY2
              Content-Type: text/plain; charset=utf-8

              $SUBJECT

              --MAIL_BOUNDARY2
              Content-Type: text/html; charset=utf-8

              --OEF--
              cat MailBody.html

              cat << --OEF--

              --MAIL_BOUNDARY2--

              --MAIL_BOUNDARY
              Content-Type: application/zip; name=file.zip
              Content-Disposition: attachment; filename=file.zip
              Content-Transfer-Encoding: base64

              --OEF--
              base64 /opt/file.zip
              cat << --OEF--

              --MAIL_BOUNDARY--
              --OEF--
              ) | /usr/sbin/sendmail $TO_ADDRESS





              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                Using sendmail:



                TO_ADDRESS="abc@example.com"
                SUBJECT="Test Mail"

                cat << --OEF--
                Subject: $SUBJECT
                TO: $TO_ADDRESS
                MIME-Version: 1.0
                Content-Type: multipart/mixed;
                boundary="MAIL_BOUNDARY"


                --MAIL_BOUNDARY
                Content-Type: multipart/alternative;
                boundary="MAIL_BOUNDARY2"

                --MAIL_BOUNDARY2
                Content-Type: text/plain; charset=utf-8

                $SUBJECT

                --MAIL_BOUNDARY2
                Content-Type: text/html; charset=utf-8

                --OEF--
                cat MailBody.html

                cat << --OEF--

                --MAIL_BOUNDARY2--

                --MAIL_BOUNDARY
                Content-Type: application/zip; name=file.zip
                Content-Disposition: attachment; filename=file.zip
                Content-Transfer-Encoding: base64

                --OEF--
                base64 /opt/file.zip
                cat << --OEF--

                --MAIL_BOUNDARY--
                --OEF--
                ) | /usr/sbin/sendmail $TO_ADDRESS





                share|improve this answer












                Using sendmail:



                TO_ADDRESS="abc@example.com"
                SUBJECT="Test Mail"

                cat << --OEF--
                Subject: $SUBJECT
                TO: $TO_ADDRESS
                MIME-Version: 1.0
                Content-Type: multipart/mixed;
                boundary="MAIL_BOUNDARY"


                --MAIL_BOUNDARY
                Content-Type: multipart/alternative;
                boundary="MAIL_BOUNDARY2"

                --MAIL_BOUNDARY2
                Content-Type: text/plain; charset=utf-8

                $SUBJECT

                --MAIL_BOUNDARY2
                Content-Type: text/html; charset=utf-8

                --OEF--
                cat MailBody.html

                cat << --OEF--

                --MAIL_BOUNDARY2--

                --MAIL_BOUNDARY
                Content-Type: application/zip; name=file.zip
                Content-Disposition: attachment; filename=file.zip
                Content-Transfer-Encoding: base64

                --OEF--
                base64 /opt/file.zip
                cat << --OEF--

                --MAIL_BOUNDARY--
                --OEF--
                ) | /usr/sbin/sendmail $TO_ADDRESS






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 16 at 17:39









                SivaPrasath

                6,23143255




                6,23143255






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f428805%2fsend-mail-with-an-attachment-and-body-of-mail-with-table-format%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    Peggy Mitchell

                    Palaiologos

                    The Forum (Inglewood, California)