How to send HTML email using linux command line

前端 未结 11 2094
无人共我
无人共我 2020-11-28 04:29

I need to send email with html format. I have only linux command line and command \"mail\".

Currently have used:

echo \"To: address@example.com\" >         


        
11条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 04:33

    Command Line

    Create a file named tmp.html with the following contents:

    my bold message
    

    Next, paste the following into the command line (parentheses and all):

    (
      echo To: youremail@blah.com
      echo From: el@defiant.com
      echo "Content-Type: text/html; "
      echo Subject: a logfile
      echo
      cat tmp.html
    ) | sendmail -t
    

    The mail will be dispatched including a bold message due to the element.

    Shell Script

    As a script, save the following as email.sh:

    ARG_EMAIL_TO="recipient@domain.com"
    ARG_EMAIL_FROM="Your Name "
    ARG_EMAIL_SUBJECT="Subject Line"
    
    (
      echo "To: ${ARG_EMAIL_TO}"
      echo "From: ${ARG_EMAIL_FROM}"
      echo "Subject: ${ARG_EMAIL_SUBJECT}"
      echo "Mime-Version: 1.0"
      echo "Content-Type: text/html; charset='utf-8'"
      echo
      cat contents.html
    ) | sendmail -t
    

    Create a file named contents.html in the same directory as the email.sh script that resembles:

    Subject Line
    
      

    HTML Content

    Run email.sh. When the email arrives, the HTML Content text will appear red.

    Related

    • How to send a html email with the bash command "sendmail"?

提交回复
热议问题