Sending mail from a Bash shell script

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

    Actually, "mail" works just as well.

    mail -s "subject line" name@address.ext < filename
    

    works perfectly fine, as long as you have SMTP set up on your machine. I think that most Macs do, by default.

    If you don't have SMTP, then the only thing you're going to be able to do is go through Mail.app. An ALTERNATIVE way to go through mail.app is via AppleScript. When you tell Mail.app to send mail via AppleScript you can tell it to not pop up any windows... (this does still require Mail.app to be configured).

    Introduction to Scripting Mail has a good description of how to work with mail in AppleScript.

提交回复
热议问题