Sending mail with attachment(image) using sendmail in Linux(ksh)

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












0














I am trying to send a mail with below command. I am sending this command from sqr to the command line, which is working fine. $FilePath_mail have To,From and other information along with mail body which is in HTML format. I want to have an image (logo) in the body, so I wanted to send it as an attachment.



/usr/sbin/sendmail -t < $FilePath_mail


I need to change the above command to add the attachment(basically an image) to the mail?










share|improve this question























  • Pure sendmail doesn't support attachments, use mutt instead.
    – Ipor Sircer
    Dec 13 at 12:58






  • 1




    sendmail does not care what you send. But if you want attachments you need to handle the MIME encoding yourself. If we can choose not to use sendmail then mail or mailx would be more lightweight than mutt.
    – Claus Andersen
    Dec 13 at 13:32















0














I am trying to send a mail with below command. I am sending this command from sqr to the command line, which is working fine. $FilePath_mail have To,From and other information along with mail body which is in HTML format. I want to have an image (logo) in the body, so I wanted to send it as an attachment.



/usr/sbin/sendmail -t < $FilePath_mail


I need to change the above command to add the attachment(basically an image) to the mail?










share|improve this question























  • Pure sendmail doesn't support attachments, use mutt instead.
    – Ipor Sircer
    Dec 13 at 12:58






  • 1




    sendmail does not care what you send. But if you want attachments you need to handle the MIME encoding yourself. If we can choose not to use sendmail then mail or mailx would be more lightweight than mutt.
    – Claus Andersen
    Dec 13 at 13:32













0












0








0







I am trying to send a mail with below command. I am sending this command from sqr to the command line, which is working fine. $FilePath_mail have To,From and other information along with mail body which is in HTML format. I want to have an image (logo) in the body, so I wanted to send it as an attachment.



/usr/sbin/sendmail -t < $FilePath_mail


I need to change the above command to add the attachment(basically an image) to the mail?










share|improve this question















I am trying to send a mail with below command. I am sending this command from sqr to the command line, which is working fine. $FilePath_mail have To,From and other information along with mail body which is in HTML format. I want to have an image (logo) in the body, so I wanted to send it as an attachment.



/usr/sbin/sendmail -t < $FilePath_mail


I need to change the above command to add the attachment(basically an image) to the mail?







sendmail images html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 13 at 14:30









Rui F Ribeiro

38.8k1479128




38.8k1479128










asked Dec 13 at 12:40









balakrishnaps

11




11











  • Pure sendmail doesn't support attachments, use mutt instead.
    – Ipor Sircer
    Dec 13 at 12:58






  • 1




    sendmail does not care what you send. But if you want attachments you need to handle the MIME encoding yourself. If we can choose not to use sendmail then mail or mailx would be more lightweight than mutt.
    – Claus Andersen
    Dec 13 at 13:32
















  • Pure sendmail doesn't support attachments, use mutt instead.
    – Ipor Sircer
    Dec 13 at 12:58






  • 1




    sendmail does not care what you send. But if you want attachments you need to handle the MIME encoding yourself. If we can choose not to use sendmail then mail or mailx would be more lightweight than mutt.
    – Claus Andersen
    Dec 13 at 13:32















Pure sendmail doesn't support attachments, use mutt instead.
– Ipor Sircer
Dec 13 at 12:58




Pure sendmail doesn't support attachments, use mutt instead.
– Ipor Sircer
Dec 13 at 12:58




1




1




sendmail does not care what you send. But if you want attachments you need to handle the MIME encoding yourself. If we can choose not to use sendmail then mail or mailx would be more lightweight than mutt.
– Claus Andersen
Dec 13 at 13:32




sendmail does not care what you send. But if you want attachments you need to handle the MIME encoding yourself. If we can choose not to use sendmail then mail or mailx would be more lightweight than mutt.
– Claus Andersen
Dec 13 at 13:32










2 Answers
2






active

oldest

votes


















0














You need to add the image as a MIME part to the mail and then reference it using the Content-ID (CID) already answered here



The people behind Courier MTA have made the utility makemime. It will be installed as part of Courier MTA but on some systems it is an independent package or as part of the maildrop utility.



The makemime makes it easier to MIME encode your mail messages from the commandline. The example from their page is:




For example:




# Take two files containing the text and the html version of a message, and
# add MIME headers to them.

makemime -c "text/plain; charset=iso-8859-1" -o tmp1.txt msg.txt
makemime -c "text/html; charset=iso-8859-1" -o tmp1.html msg.html

# Combine the result into a multipart/alternative collection

makemime -m "multipart/alternative" -a "Content-Disposition: inline"
-o tmp.ma1 tmp1.txt
makemime -j tmp.ma1 -o tmp.ma2 tmp1.html

# Add MIME headers to an image attachment.

makemime -c "image/gif" -a "Content-Disposition: attachment"
-o tmp2.gif attachment.gif

# Create the final multipart/mixed collection

makemime -m "multipart/mixed" -a "Mime-Version: 1.0"
-o tmp.mm1 tmp.ma2
makemime -j tmp.mm1 -o output.msg tmp2.gif



output.msg now contains the complete MIME collection. Just add the Subject:, From:, and To: headers (can also be done by additional -a options, of course), and send it on its way.




This is what you are asking - and it can be done. Using a tool like makemime makes the process fairly safe.



You should however read the Sendgrid article on "How to Embed Images in Your Emails: The Facts". Because of poor handling in many clients I usually just end up referencing the image on a web server. It is the easiest method and even though it often requires the user to "click to view" it seems to give the most consistent results across clients.



Another option is to inline embed the logo in your HTML source.



 <img alt="Logo" src="data:image/jpeg;base64,">


or



 <img alt="Logo" src="data:image/png;base64,"


Add the base64 encoded data of the image file right after base64, and you are good to go. But again many clients will not like it.



You can encode the file online with base64encode.org. I would highly recommend to compress the image first using something like TinyPNG






share|improve this answer




























    0














    In case you opt just for sending the image, you can always send an image via email with mpack



    The syntax as you need it, is roughly:



    mpack -s "This is my image" $FilePath_mail bill@domain.com


    From man mpack




    NAME



     mpack - pack a file in MIME format


    DESCRIPTION
    The mpack program encodes the the named file in one or more MIME messages. The
    resulting messages are mailed to one or more recipients, written to a named file
    or set of files, or posted to a set of newsgroups.




    In Debian, you install it as in:



    sudo apt-get install mpack





    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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      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%2f487750%2fsending-mail-with-attachmentimage-using-sendmail-in-linuxksh%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You need to add the image as a MIME part to the mail and then reference it using the Content-ID (CID) already answered here



      The people behind Courier MTA have made the utility makemime. It will be installed as part of Courier MTA but on some systems it is an independent package or as part of the maildrop utility.



      The makemime makes it easier to MIME encode your mail messages from the commandline. The example from their page is:




      For example:




      # Take two files containing the text and the html version of a message, and
      # add MIME headers to them.

      makemime -c "text/plain; charset=iso-8859-1" -o tmp1.txt msg.txt
      makemime -c "text/html; charset=iso-8859-1" -o tmp1.html msg.html

      # Combine the result into a multipart/alternative collection

      makemime -m "multipart/alternative" -a "Content-Disposition: inline"
      -o tmp.ma1 tmp1.txt
      makemime -j tmp.ma1 -o tmp.ma2 tmp1.html

      # Add MIME headers to an image attachment.

      makemime -c "image/gif" -a "Content-Disposition: attachment"
      -o tmp2.gif attachment.gif

      # Create the final multipart/mixed collection

      makemime -m "multipart/mixed" -a "Mime-Version: 1.0"
      -o tmp.mm1 tmp.ma2
      makemime -j tmp.mm1 -o output.msg tmp2.gif



      output.msg now contains the complete MIME collection. Just add the Subject:, From:, and To: headers (can also be done by additional -a options, of course), and send it on its way.




      This is what you are asking - and it can be done. Using a tool like makemime makes the process fairly safe.



      You should however read the Sendgrid article on "How to Embed Images in Your Emails: The Facts". Because of poor handling in many clients I usually just end up referencing the image on a web server. It is the easiest method and even though it often requires the user to "click to view" it seems to give the most consistent results across clients.



      Another option is to inline embed the logo in your HTML source.



       <img alt="Logo" src="data:image/jpeg;base64,">


      or



       <img alt="Logo" src="data:image/png;base64,"


      Add the base64 encoded data of the image file right after base64, and you are good to go. But again many clients will not like it.



      You can encode the file online with base64encode.org. I would highly recommend to compress the image first using something like TinyPNG






      share|improve this answer

























        0














        You need to add the image as a MIME part to the mail and then reference it using the Content-ID (CID) already answered here



        The people behind Courier MTA have made the utility makemime. It will be installed as part of Courier MTA but on some systems it is an independent package or as part of the maildrop utility.



        The makemime makes it easier to MIME encode your mail messages from the commandline. The example from their page is:




        For example:




        # Take two files containing the text and the html version of a message, and
        # add MIME headers to them.

        makemime -c "text/plain; charset=iso-8859-1" -o tmp1.txt msg.txt
        makemime -c "text/html; charset=iso-8859-1" -o tmp1.html msg.html

        # Combine the result into a multipart/alternative collection

        makemime -m "multipart/alternative" -a "Content-Disposition: inline"
        -o tmp.ma1 tmp1.txt
        makemime -j tmp.ma1 -o tmp.ma2 tmp1.html

        # Add MIME headers to an image attachment.

        makemime -c "image/gif" -a "Content-Disposition: attachment"
        -o tmp2.gif attachment.gif

        # Create the final multipart/mixed collection

        makemime -m "multipart/mixed" -a "Mime-Version: 1.0"
        -o tmp.mm1 tmp.ma2
        makemime -j tmp.mm1 -o output.msg tmp2.gif



        output.msg now contains the complete MIME collection. Just add the Subject:, From:, and To: headers (can also be done by additional -a options, of course), and send it on its way.




        This is what you are asking - and it can be done. Using a tool like makemime makes the process fairly safe.



        You should however read the Sendgrid article on "How to Embed Images in Your Emails: The Facts". Because of poor handling in many clients I usually just end up referencing the image on a web server. It is the easiest method and even though it often requires the user to "click to view" it seems to give the most consistent results across clients.



        Another option is to inline embed the logo in your HTML source.



         <img alt="Logo" src="data:image/jpeg;base64,">


        or



         <img alt="Logo" src="data:image/png;base64,"


        Add the base64 encoded data of the image file right after base64, and you are good to go. But again many clients will not like it.



        You can encode the file online with base64encode.org. I would highly recommend to compress the image first using something like TinyPNG






        share|improve this answer























          0












          0








          0






          You need to add the image as a MIME part to the mail and then reference it using the Content-ID (CID) already answered here



          The people behind Courier MTA have made the utility makemime. It will be installed as part of Courier MTA but on some systems it is an independent package or as part of the maildrop utility.



          The makemime makes it easier to MIME encode your mail messages from the commandline. The example from their page is:




          For example:




          # Take two files containing the text and the html version of a message, and
          # add MIME headers to them.

          makemime -c "text/plain; charset=iso-8859-1" -o tmp1.txt msg.txt
          makemime -c "text/html; charset=iso-8859-1" -o tmp1.html msg.html

          # Combine the result into a multipart/alternative collection

          makemime -m "multipart/alternative" -a "Content-Disposition: inline"
          -o tmp.ma1 tmp1.txt
          makemime -j tmp.ma1 -o tmp.ma2 tmp1.html

          # Add MIME headers to an image attachment.

          makemime -c "image/gif" -a "Content-Disposition: attachment"
          -o tmp2.gif attachment.gif

          # Create the final multipart/mixed collection

          makemime -m "multipart/mixed" -a "Mime-Version: 1.0"
          -o tmp.mm1 tmp.ma2
          makemime -j tmp.mm1 -o output.msg tmp2.gif



          output.msg now contains the complete MIME collection. Just add the Subject:, From:, and To: headers (can also be done by additional -a options, of course), and send it on its way.




          This is what you are asking - and it can be done. Using a tool like makemime makes the process fairly safe.



          You should however read the Sendgrid article on "How to Embed Images in Your Emails: The Facts". Because of poor handling in many clients I usually just end up referencing the image on a web server. It is the easiest method and even though it often requires the user to "click to view" it seems to give the most consistent results across clients.



          Another option is to inline embed the logo in your HTML source.



           <img alt="Logo" src="data:image/jpeg;base64,">


          or



           <img alt="Logo" src="data:image/png;base64,"


          Add the base64 encoded data of the image file right after base64, and you are good to go. But again many clients will not like it.



          You can encode the file online with base64encode.org. I would highly recommend to compress the image first using something like TinyPNG






          share|improve this answer












          You need to add the image as a MIME part to the mail and then reference it using the Content-ID (CID) already answered here



          The people behind Courier MTA have made the utility makemime. It will be installed as part of Courier MTA but on some systems it is an independent package or as part of the maildrop utility.



          The makemime makes it easier to MIME encode your mail messages from the commandline. The example from their page is:




          For example:




          # Take two files containing the text and the html version of a message, and
          # add MIME headers to them.

          makemime -c "text/plain; charset=iso-8859-1" -o tmp1.txt msg.txt
          makemime -c "text/html; charset=iso-8859-1" -o tmp1.html msg.html

          # Combine the result into a multipart/alternative collection

          makemime -m "multipart/alternative" -a "Content-Disposition: inline"
          -o tmp.ma1 tmp1.txt
          makemime -j tmp.ma1 -o tmp.ma2 tmp1.html

          # Add MIME headers to an image attachment.

          makemime -c "image/gif" -a "Content-Disposition: attachment"
          -o tmp2.gif attachment.gif

          # Create the final multipart/mixed collection

          makemime -m "multipart/mixed" -a "Mime-Version: 1.0"
          -o tmp.mm1 tmp.ma2
          makemime -j tmp.mm1 -o output.msg tmp2.gif



          output.msg now contains the complete MIME collection. Just add the Subject:, From:, and To: headers (can also be done by additional -a options, of course), and send it on its way.




          This is what you are asking - and it can be done. Using a tool like makemime makes the process fairly safe.



          You should however read the Sendgrid article on "How to Embed Images in Your Emails: The Facts". Because of poor handling in many clients I usually just end up referencing the image on a web server. It is the easiest method and even though it often requires the user to "click to view" it seems to give the most consistent results across clients.



          Another option is to inline embed the logo in your HTML source.



           <img alt="Logo" src="data:image/jpeg;base64,">


          or



           <img alt="Logo" src="data:image/png;base64,"


          Add the base64 encoded data of the image file right after base64, and you are good to go. But again many clients will not like it.



          You can encode the file online with base64encode.org. I would highly recommend to compress the image first using something like TinyPNG







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 13 at 13:29









          Claus Andersen

          1,614414




          1,614414























              0














              In case you opt just for sending the image, you can always send an image via email with mpack



              The syntax as you need it, is roughly:



              mpack -s "This is my image" $FilePath_mail bill@domain.com


              From man mpack




              NAME



               mpack - pack a file in MIME format


              DESCRIPTION
              The mpack program encodes the the named file in one or more MIME messages. The
              resulting messages are mailed to one or more recipients, written to a named file
              or set of files, or posted to a set of newsgroups.




              In Debian, you install it as in:



              sudo apt-get install mpack





              share|improve this answer

























                0














                In case you opt just for sending the image, you can always send an image via email with mpack



                The syntax as you need it, is roughly:



                mpack -s "This is my image" $FilePath_mail bill@domain.com


                From man mpack




                NAME



                 mpack - pack a file in MIME format


                DESCRIPTION
                The mpack program encodes the the named file in one or more MIME messages. The
                resulting messages are mailed to one or more recipients, written to a named file
                or set of files, or posted to a set of newsgroups.




                In Debian, you install it as in:



                sudo apt-get install mpack





                share|improve this answer























                  0












                  0








                  0






                  In case you opt just for sending the image, you can always send an image via email with mpack



                  The syntax as you need it, is roughly:



                  mpack -s "This is my image" $FilePath_mail bill@domain.com


                  From man mpack




                  NAME



                   mpack - pack a file in MIME format


                  DESCRIPTION
                  The mpack program encodes the the named file in one or more MIME messages. The
                  resulting messages are mailed to one or more recipients, written to a named file
                  or set of files, or posted to a set of newsgroups.




                  In Debian, you install it as in:



                  sudo apt-get install mpack





                  share|improve this answer












                  In case you opt just for sending the image, you can always send an image via email with mpack



                  The syntax as you need it, is roughly:



                  mpack -s "This is my image" $FilePath_mail bill@domain.com


                  From man mpack




                  NAME



                   mpack - pack a file in MIME format


                  DESCRIPTION
                  The mpack program encodes the the named file in one or more MIME messages. The
                  resulting messages are mailed to one or more recipients, written to a named file
                  or set of files, or posted to a set of newsgroups.




                  In Debian, you install it as in:



                  sudo apt-get install mpack






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 13 at 14:33









                  Rui F Ribeiro

                  38.8k1479128




                  38.8k1479128



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487750%2fsending-mail-with-attachmentimage-using-sendmail-in-linuxksh%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown






                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?