Config 5.3: Sending Emails

The Blk Block

Genelet has built-in services to send email, push notification and SMS. To use them, define the following keys in Blk, with values for system and connection parameters.

  • Mail: sending emails using SMTP.
  • Apple: sending APNS.
  • Google: sending GCM.
  • Sms: sending SMS text messages.

It is important to note that the services, if enabled, run in a sequence at the end of request. It blocks each other, as well as the original web request. If your web server has a slow or unreliable connection to the service providers, you should look for non-blocking solutions such as message queue service.

Email Service

The Mail configuration is:

"Mail": {
  "Username": string (optional),
  "Password": string (optional),
  "SSL": bool (optional),
  "Address": string,
  "From": string,
  "Headers": {key:value, key:value}
}

where Address is the internet address of the SMTP host; Username and Password are the SMTP user account; and From is the generic email address of the sender belonging to this project. All the other system and connection parameters are put in Headers as key-value pairs.

Sending Email

You should send email at the end of a request, e.g. after a successful member signup. Just to add key _gmail to the output data structure other (see Developer Manual in each language):

"_gmail": {
  "To"     : string,
  "Subject": string,
  "Content": string,
  "File"   : string,
  "Extra"  : {key: value, key: value, ...},
  key, value,
  key, value
}

where To is the recipient email address, Subject the subject and Content the body. If Content is not given, Genelet will use the value of File, the template located under the same directory as HTML templates, and optionally, extra key-values Extra, to construct the message body. For any other possible extra key-value pairs required by the SMTP service, put them directly into _gmail.