Google usually has all the answers
You’ll need to use SSL to send messages through Gmail.
Something like this:
-- Michal Kottman, 2011, public domain local socket = require 'socket' local smtp = require 'socket.smtp' local ssl = require 'ssl' local https = require 'ssl.https' local ltn12 = require 'ltn12' function sslCreate() local sock = socket.tcp() return setmetatable({ connect = function(\_, host, port) local r, e = sock:connect(host, port) if not r then return r, e end sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'}) return sock:dohandshake() end }, { \_\_index = function(t,n) return function(\_, ...) return sock[n](sock, ...) end end }) end function sendMessage(subject, body) local msg = { headers = { to = 'Your Target \<target email\>', subject = subject }, body = body } local ok, err = smtp.send { from = '\<your email\>', rcpt = '\<target email\>', source = smtp.message(msg), user = 'username', password = 'password', server = 'smtp.gmail.com', port = 465, create = sslCreate } if not ok then print("Mail send failed", err) -- better error handling required end end
Source: http://stackoverflow.com/questions/11070623/lua-send-mail-with-gmail-account