Task

Write a function to send an email.

The function should have parameters for setting From, To and Cc addresses; the Subject, and the message text, and optionally fields for the server name and login details.

 If appropriate, explain what notifications of problems/success are given.
 Solutions using libraries or functions from the language are preferred, but failing that, external programs can be used with an explanation.
 Note how portable the solution given is between operating systems when multi-OS languages are used.


(Remember to obfuscate any sensitive data used in examples)




----------------------------------------
-- 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] - optional; 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