How to send an email from command line or script? I want to be able to run the script programmatically by passing the receiver and the message.
|
|
|
|||
|
|
Since it's Unix based, you can use sendmail command. |
|||
|
|
|
There are two programs that I am aware of which will easily allow you to configure your Mac to send email from the command line. I have written up HOWTOs for both of them: Of the two, I suggest Configuration is complicated enough that I'm not sure if I should replicate all of the steps here, but I will mention that if you use Homebrew you can install msmtp using
Then the rest is just a matter of setting up the related configuration files The first is
Note that I put mine in Then you need a
The last but crucial step is making sure your Keychain has the information exactly in the format that msmtp will expect it:
I think that covers most of the details. See http://www.tuaw.com/2010/05/04/msmtp-a-free-tool-to-send-email-from-terminal/ if you want a few more specifics. |
|||
|
|
The most basic way to send mail is trough a telnet session with the smtp server of your provider/network. After you contacted the server and after every command the server will answer if it accepts the command with something like "250 OK", or if not with an error message. All details can be found in RFC2821 - Simple Mail Transfer Protocol, Google for it. This basic way is great for testing why something goes wrong sending mail, but I think it's quite complicated to script it full proof. First get an command-line interface on your computer, by starting Terminal. Then continue with the following commands, one after one. Open a telnet session to port 25 of the smtp server of your provider/network
say hello plus the internetname of your provider/network, like abc.com
a from=return address is needed, the < and > are part of the command
give one or more destinations, the < and > are part of the command
tell the server you want start sending data
now the server should answer you can start sending your mail and goes into data-mode
now finish data with a dot as only char on a line
the server goes back to command-mode so you can quit
|
|||
|
|
|
mtcmail is another option: http://www.macupdate.com/app/mac/33505/mtcmail-cli. [Ignore this additional text. Added because: body must be at least 30 characters; you entered 27.] |
|||
|
|
