An open API service indexing awesome lists of open source software.

https://github.com/ibm-cloud/cloudmailer

IBM Cloud Functions action to send out email via SMTP
https://github.com/ibm-cloud/cloudmailer

ibm-cloud ibm-cloud-functions nodemailer openwhisk serverless smtp

Last synced: 6 months ago
JSON representation

IBM Cloud Functions action to send out email via SMTP

Awesome Lists containing this project

README

          

# Send emails using IBM Cloud Functions
Use a simple [IBM Cloud Functions](https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-getting-started) action to send out emails via SMTP. Pass in the SMTP server configuration and the email using JSON objects.
For ease of use, bind the server configuration to the action and only pass in the email to send.

The following screenshot shows an email based on [this sample properties](email.blog.json).

![sample email](images/20210609_Sample_Email.png)

See the blog post [A Serverless Function for Sending Emails on IBM Cloud](https://www.ibm.com/cloud/blog/a-serverless-function-for-sending-emails-on-ibm-cloud) for some background and more links.

## Deploy

### Using the IBM Cloud CLI
Use the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-getting-started) and the [Cloud Functions plugin](https://cloud.ibm.com/docs/cli?topic=cloud-functions-cli-plugin-functions-cli) to deploy the action. Log in to IBM Cloud, [set the namespace](https://cloud.ibm.com/docs/cli?topic=cloud-functions-cli-plugin-functions-cli#cli_namespace_target) and then run:

```sh
ibmcloud fn deploy -m Cloudmailer.yaml
```

Copy over [smtp_config.sample.json](smtp_config.sample.json) to, e.g., **smtp_config.sendgrid.json**. Then adapt the file (see [SMTP server configuration](#smtp-server-configuration)) and use it to set the SMTP configuration as default:

```sh
ibmcloud fn action update cloudmailer/sendEmail -P smtp_config.sendgrid.json
```

Be aware that typically the port 25 is blocked. Many email providers are using ports like 465 or 587.

Instead of using the IBM Cloud CLI, you can also go to the [IBM Cloud Functions portal](https://cloud.ibm.com/functions/) and create the action there. Use the source from [smtp_email.js](smtp_email.js) for the action.

### Using Terraform

Go into the [tf](tf) directory. You may want to adapt the [provider configuration file](tf/provider.tf) to match your overall environment. Either change [tf/variables.tf](tf/variables.tf) or better override some values in a separate **terraform.tfvars** file. There, you may want to set the IBM Cloud API key to use and change the SMTP server configuration. Set the variable **server_config** similar to shown in the file **variables.tf**, e.g., for SendGrid:

```
server_config= <