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
- Host: GitHub
- URL: https://github.com/ibm-cloud/cloudmailer
- Owner: IBM-Cloud
- License: apache-2.0
- Created: 2021-06-08T09:13:44.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-06-15T06:50:19.000Z (almost 5 years ago)
- Last Synced: 2025-01-17T18:18:21.051Z (about 1 year ago)
- Topics: ibm-cloud, ibm-cloud-functions, nodemailer, openwhisk, serverless, smtp
- Language: JavaScript
- Homepage: https://www.ibm.com/cloud/blog/a-serverless-function-for-sending-emails-on-ibm-cloud
- Size: 50.8 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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).

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= <