I'm wondering if it would be possible to send an email from a lua script. I am using linux so I do have the mail
command, but I can't work out how to use it.
Any help would be much appreciated.
LuaSocket offers support for sending email:
http://w3.impa.br/~diego/software/luasocket/smtp.html
You've probably already found a solution, but since this question still shows up in google, here's another answer that works on linux:
mail = io.popen("mail -s 'SUBJECT' [email protected]", "w")
mail:write("testing some stuff\n\4")
-- tested with lua 5.2 on ubuntu server
io.popen opens the mail program as a file as explained in the lua reference manual. It is important to open it in writing mode ("w") to be able to actually write the body of the email. Then you just write your message with :write and when you're done, append a newline character "\n" followed by a EOT "\4" character to tell the program to send the message.
This method has the advantage that you do not need to handle the sending of the message yourself, as with the LuaSocket library and that you don't need to have SMTP support on your mail server enabled, which can be a lot of work to set up propperly and the disadvantage that you need to have access to mailx, so you can't send messages from anywhere.
Hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With