Send email

From Rosetta Code
Revision as of 19:33, 20 October 2016 by rosettacode>Fluxus (Lingo added)

Lingo

Lingo has no built-in support for sending email. But this can be achieved e.g. by using Shell Xtra and one of the available command-line SMTP clients.

Library: Shell Xtra

<lang lingo>


-- Sends email via SMTP using senditquiet.exe (15 KB) -- @param {string} fromAddr -- @param {string} toAddr - multiple addresses separated with ; -- @param {string} subject -- @param {string} message - use "\n" for line breaks -- @param {string} [cc=VOID] - optional; multiple addresses separated with ; -- @param {string} [bcc=VOID] - optional; multiple addresses separated with ; -- @param {propList} [serverProps=VOID] - allows to overwrite default settings -- @return {bool} success


on sendEmail (fromAddr, toAddr, subject, message, cc, bcc, serverProps)

 sx = xtra("Shell").new()
 
 -- senditquiet.exe in folder "bin" relative to current movie
 sx.shell_setcurrentdir(_movie.path&"bin")
 
 -- defaults
 host = "smtp.gmail.com"
 protocol = "ssl"
 port = 587
 user = "johndoe"
 pass = "foobar"
 
 -- if propList 'serverProps' was passed, overwrite defaults
 if ilk(serverProps)=#propList then
   repeat with i = 1 to serverProps.count
     do(serverProps.getPropAt(i)&"="&QUOTE&serverProps[i]&QUOTE)
   end repeat
 end if
 cmd = "senditquiet"
 put " -s "&host after cmd
 put " -protocol "&protocol after cmd
 put " -port "&port after cmd
 put " -u "&user after cmd
 put " -p "&pass after cmd
 
 put " -f "&QUOTE&fromAddr&QUOTE after cmd
 put " -t "&QUOTE&toAddr&QUOTE after cmd
 put " -subject "&QUOTE&subject&QUOTE after cmd
 put " -body "&QUOTE&message&QUOTE after cmd
 
 -- optional args
 if not voidP(cc) then put " -cc "&QUOTE&cc&QUOTE after cmd
 if not voidP(bcc) then put " -bcc "&QUOTE&bcc&QUOTE after cmd
 put "1>nul 2>nul&if errorlevel 1 echo ERROR" after cmd
 
 res = sx.shell_cmd(cmd)
 return not(res contains "ERROR")  

end</lang>