Sending mail from a Bash shell script

前端 未结 12 1498
梦毁少年i
梦毁少年i 2021-01-29 22:54

I am writing a Bash shell script for Mac that sends an email notification by opening an automator application that sends email out with the default mail account in Mail.app. The

12条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 23:42

    sendmail and even postfix may be too big to install if all you want to do is to send a few emails from your scripts.

    If you have a Gmail account for example, you can use Google's servers to send email using SMTP. If you don't want to use gGoogle's server, as long as you have access to some SMTP server, it should work.

    A very lightweight program that makes it easy to do so is msmtp. They have examples of configuration files in their documentation.

    The easiest way to do it would be to set up a system-wide default:

    account default
    host smtp.gmail.com
    from john.doe@gmail.com
    user john.doe@gmail.com
    password XXX
    port 587
    

    msmtp should be very easy to install. In fact, there is a port for it, so it could be as easy as port install msmtp.

    After installing and configuring msmtp, you can send email to john.doe@gmail.com using:

    mail -s  john.doe@gmail.com <.
    EOF
    

    You can put the above in a script. See man mail for details.

提交回复
热议问题