Urgent request ! Sending Email in the background

Hi Team,

I need your urgent help in how to send email in the background. I mean if I have form with some fields then user can fill the form then click on send  then it should go to some email externally after formatting the email body…

I dont want to have email pop-up after the user clicks on send …

Is this possible and how … please advice.

Regards

Abdulaziz

Here’s a rather old topic which might be worth investigating.

https://forums.coronalabs.com/topic/16136-smtp-send-email-with-attachment-using-luasocket/

Hi ingemar,

I tried the code the following code but no luck .

local socket = require 'socket' smtp = require("socket.smtp") ltn12 = require("ltn12") function sendMessage(subject, body) local msg = { headers = { to = 'alzaabi98@gmail.com', subject = subject }, body = body } local ok, err = smtp.send { from = 'alzaabi98@gmail.com', rcpt = 'alzaabi98@gmail.com', source = smtp.message(msg), user = 'sometghing@gmail.com', password = '\*\*\*', server = 'smtp.gmail.com', port = 465, } if not ok then print("Mail send failed", err) -- better error handling required end end sendMessage("test from lua", " hellow there")

I got this error :

"Mail send failed closed "

please advice

Google usually has all the answers  :wink:

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

i tried it but it does not work , i got this error  :

does that mean ssl is not supported ??

Module ‘ssl’ not found:

no field package.preload[‘ssl’]

no file ‘/Users/abdulaziz/Library/Application Support/Corona/Simulator/Plugins/ssl.lua’

no file ‘/Users/abdulaziz/Documents/CoronaProjects/Fuel Cosume/ssl.lua’

no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/ssl.lua’

no file ‘/Users/abdulaziz/Library/Application Support/Corona/Simulator/Plugins/ssl.dylib’

no file ‘./ssl.dylib’

no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/ssl.dylib’

Corona has this plugin for ssl which may work.https://docs.coronalabs.com/plugin/openssl/

I could not figure out to use to replace that code… my skills is not up to this level 

Did you add the plugin to your build.settings?

Another source of information would be to use network.request()
https://docs.coronalabs.com/api/library/network/request.html

yes Scott , i did  but no luck … i am finding the way to send email via ssl… in the lua example they are doing it via ssl function which i could not find a way to make with openssl … 

Hi @alzaabi98,

Did you finally was able to successfully sending your email ? If so, would you be open to share your final code ?

thanks,
Nick

Hi @nmichaud

That was just part of test project long back … if I recall well I did send to web service as post request and then the web service send email via email gateway

I used mailgun and php for that

Let me know if this helped

Here’s a rather old topic which might be worth investigating.

https://forums.coronalabs.com/topic/16136-smtp-send-email-with-attachment-using-luasocket/

Hi ingemar,

I tried the code the following code but no luck .

local socket = require 'socket' smtp = require("socket.smtp") ltn12 = require("ltn12") function sendMessage(subject, body) local msg = { headers = { to = 'alzaabi98@gmail.com', subject = subject }, body = body } local ok, err = smtp.send { from = 'alzaabi98@gmail.com', rcpt = 'alzaabi98@gmail.com', source = smtp.message(msg), user = 'sometghing@gmail.com', password = '\*\*\*', server = 'smtp.gmail.com', port = 465, } if not ok then print("Mail send failed", err) -- better error handling required end end sendMessage("test from lua", " hellow there")

I got this error :

"Mail send failed closed "

please advice

Google usually has all the answers  :wink:

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

i tried it but it does not work , i got this error  :

does that mean ssl is not supported ??

Module ‘ssl’ not found:

no field package.preload[‘ssl’]

no file ‘/Users/abdulaziz/Library/Application Support/Corona/Simulator/Plugins/ssl.lua’

no file ‘/Users/abdulaziz/Documents/CoronaProjects/Fuel Cosume/ssl.lua’

no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/ssl.lua’

no file ‘/Users/abdulaziz/Library/Application Support/Corona/Simulator/Plugins/ssl.dylib’

no file ‘./ssl.dylib’

no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/ssl.dylib’

Corona has this plugin for ssl which may work.https://docs.coronalabs.com/plugin/openssl/

I could not figure out to use to replace that code… my skills is not up to this level 

Did you add the plugin to your build.settings?

Another source of information would be to use network.request()
https://docs.coronalabs.com/api/library/network/request.html