How to send HTML email using linux command line

前端 未结 11 2088
无人共我
无人共我 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:48

    With heirloom-mailx you can change sendmail program to your hook script, replace headers there and then use sendmail.

    The script I use (~/bin/sendmail-hook):

    #!/bin/bash
    
    sed '1,/^$/{
    s,^\(Content-Type: \).*$,\1text/html; charset=utf-8,g
    s,^\(Content-Transfer-Encoding: \).*$,\18bit,g
    }' | sendmail $@
    

    This script changes the values in the mail header as follows:

    • Content-Type: to text/html; charset=utf-8
    • Content-Transfer-Encoding: to 8bit (not sure if this is really needed).

    To send HTML email:

    mail -Ssendmail='~/bin/sendmail-hook' \
        -s "Built notification" address@example.com < /var/www/report.csv
    

提交回复
热议问题