[SOL-381] Send an EMAIL from Lua script Created: 21.04.2016  Updated: 27.07.2020  Resolved: 27.07.2020

Status: Obsolete
Project: Solution Center
Component/s: EXASolution
Affects Version/s: None
Fix Version/s: None

Type: How To
Reporter: Captain EXASOL Assignee: Captain EXASOL
Labels: Lua

Issue Links:
Related
Solution:

Note: This solution is no longer maintained. For the latest information, please refer to our documentation:

https://community.exasol.com/t5/database-features/send-an-email-from-lua-script/ta-p/1448

Background

The solution described below uses the 'socket' package.

Detailed documentation on the package can be found here: http://w3.impa.br/~diego/software/luasocket/smtp.html

No further installation is needed since 'socket' is part of EXASOLs distribution.

Solution using a Lua Script

CREATE LUA SCRIPT "SEND_MAIL" ()
RETURNS ROWCOUNT AS

  smtp = require('socket.smtp')

  sender = 'service@exasol.com'
  receivers = { 'captain.exasol@exasol.com' } -- use a dictionary
  message_text = 'hello world'
	
  -- put the message contents into a dictionary:  
  mesgt = {
    -- SMTP headers
    headers = {
      to = 'Captain EXASOL <captain.exasol@exasol.com>',
      from = 'EXASOL Service <service@exasol.com>',
      subject = 'The mail you requested'
    },
    -- message body
    body = message_text
  }
	
  -- send mail using an SMTP server
  res, err = smtp.send{
    from = sender,
    rcpt = receivers, 
    source = smtp.message(mesgt),
    -- you have to know/ask for the correct mail server, our cluster does not know any.
    -- if the cluster has no DNS service, you need to use an IP address
    server = 'mail.exasol.com'
  }

  if err then
    error(err)
  end
/

Additional Notes

Ideas / Extensions

Provide Parameters for all parts of a mail like

  • receiver(s)
  • subject
  • text
Category 1: Scripting
Category 2: ETL / Data Integration
Generated at Mon May 17 03:30:56 CEST 2021 using Jira 7.13.18#713018-sha1:e1230154f8ff8cc9272975bf568fc732e806fd68.