This is a tested sample. Obviously the email addresses, host names, ports, passwords, etc. will need to be replaced with the actual ones you plan to use. There are two parts to this example. The button script will go in a buttons clicked script. All it does is run the email function passing it a message (must be a string) as a parameter. The email function goes in the screen load script.
--Button Script
email('Hello from a Mach4 machine') --This calls the email function and passes it a message.
--Screen Load Script
---------------------------------------------------------------
-- Email added 8-30-2016
---------------------------------------------------------------
--Helpful link http://w3.impa.br/~diego/software/luasocket/smtp.html
function email(message)
package.path = package.path .. ';./Modules/?.lua;'
package.cpath = package.cpath .. ';./Modules/?.dll;'
-- load the smtp support
local smtp = require('/socket.smtp')
from = '<fromname@hostname.net>' --email address of sender
rcpt = {
'<toname1@hostname.net>', --email address of recipient
'<toname2@hostname.net>', --email address of carbon copied recipient
'<toname3@hostname.net>' --email address of blind carbon copied recipient. They will be blind because we will not list them in the header
}
mesgt = {
headers = {
from = 'From Name <fromname@hostname.net>', --name and email address of sender. Example: 'John Doe <originaljdoe@anyhost.net>'
to = 'To Name <toname1@hostname.net>', --name and email address of recipient
cc = 'To Name <toname2@hostname.net>', --name and email address of someone being carbon copied
subject = 'Mail from a Mach4 machine' --email subject
},
body = tostring(message)
}
r, e = smtp.send{
from = from,
rcpt = rcpt,
source = smtp.message(mesgt),
server = 'mail.myhost.net', --this is the address or IP of the mail server used to send this email. smtp.gmail.com is one example
password = 'MailServerPassword', --this is the password you use to access the mail server you are sending from
user = 'myname@myhost.net' --this is the user name you use to access the mail server you are sending from
}
if (r == 1) then --Message was sent successfully
wx.wxMessageBox('Message was sent successfully.')
else --There was an error
wx.wxMessageBox('!!!ERROR!!!\n\n' .. tostring(e))
end
end