Sending HTML mail using a shell script

前端 未结 13 1482
死守一世寂寞
死守一世寂寞 2020-11-28 03:46

How can I send an HTML email using a shell script?

13条回答
  •  星月不相逢
    2020-11-28 04:36

    Another option is using msmtp.

    What you need is to set up your .msmtprc with something like this (example is using gmail):

    account default
    host smtp.gmail.com
    port 587
    from example@gmail.com
    tls on
    tls_starttls on
    tls_trust_file ~/.certs/equifax.pem
    auth on
    user example@gmail.com
    password 
    logfile ~/.msmtp.log
    

    Then just call:

    (echo "Subject: "; echo; echo "") | msmtp 
    

    in your script

    Update: For HTML mail you have to put the headers as well, so you might want to make a file like this:

    From: sender@domain.tld
    To: email@domain.tld
    Subject: Important message
    Mime-Version: 1.0
    Content-Type: text/html
    
    

    Mail body will be here

    The mail body should start after one blank line from the header.

    And mail it like

    cat email-template | msmtp email@domain.tld
    

    The same can be done via command line as well, but it might be easier using a file.

提交回复
热议问题