Sending mail from a Bash shell script

前端 未结 12 1518
梦毁少年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

    Here is a simple Ruby script to do this. Ruby ships on the Mac OS X versions you mentioned.

    Replace all the bits marked 'replace'. If it fails, it returns a non-zero exit code and a Ruby back trace.

    require 'net/smtp'
    
    SMTPHOST = 'replace.yoursmtpserver.example.com'
    FROM = '"Your Email" '
    
    def send(to, subject, message)
      body = <

    You can embed this in a Bash script like so:

    ruby << EOF
     ... script here ...
    EOF
    

    For some other ways to send Ruby emails, see Stack Overflow question How do I send mail from a Ruby program?.

    You can use other languages that ship with Mac OS X as well:

    • How do I send email with Perl?
    • Sending HTML email using Python

提交回复
热议问题