How to send an email through the Oracle Cloud Email Delivery service via Node’s Nodemailer package
This tutorial continues from our last article: Oracle Cloud: Email Delivery using Mailx and will adopt the same initial steps but instead of using Mailx, will use Python.
The Oracle Cloud Infrastructure provides an Email Delivery service that enables users to send bulk emails to their recipients. The official documentation to get started lies here.
This tutorial lays out the basic steps to accomplishing email sending using this service via Mailx referencing the official tutorial and the Nodemailer guide here.
Cost
From that same website, we see the current cost of sending emails. The FAQ states one email is equivalent to 2 MB or one recipient in the To, CC, or BCC fields.
Screenshot of Oracle Cloud website that shows the current price of the email delivery at $0.00 for the first 3100 emails and $0.085 for every 1000 emails above that
Set up Email Delivery service on OCI
First, you need to set up the Email Delivery service on OCI.
- Create an SMTP Credential. Click your profile picture and click Generate credentials in SMTP credentials. Make sure to save the user and password info:
2. Go to the Email Delivery service
3. Create an Approved Sender using an email in a server you control or a random email that may not even exist (I use fdurrani@ulhqlkypwzshkgqhwqfb.com which does not exist). This will be your From email.
Note that sending emails from unverified domains may lead to email bounces, quarantine, or restrictions of the recipient from receiving your email:
4. Navigate to the Configuration tab of Email Delivery and copy the information on the page:
Send email
Copy paste the following NodeJS code (adapted from the linked blog post), replacing the SENDER
, RECIPIENT
, USERNAME_SMTP
, HOST
, PORT
, and password_smtp
with your own. Be sure to do npm install nodemailer
to install the package first.
import nodemailer from "nodemailer";
const transporter = nodemailer.createTransport({
pool: true,
host: "smtp.email.us-ashburn-1.oci.oraclecloud.com",
port: 587,
secure: false,
auth: {
user: "ocid1.user.oc1..aaaaaaaaaznjxw5fvpuizguxf5avbsje6sbta7j53oh3gyhiorp73fq@ocid1.tenancy.oc1..aaaaaaaaaeve7ubmplo4cxobeukpwp2uaiuusekfkut3hcvblaanpa.go.com",
pass: "0jfpB;uQpAjh_u!a",
},
});
const message = {
from: '"Faris Durrani"fdurrani@ulhqlkypwzshkgqhwqfb.com',
to: "fdurrani@mythics.com",
subject: "Message title",
text: "Plaintext version of the message",
html: "<p>HTML version of the message</p>",
};
transporter.sendMail(message, (err, info) => {
if (err) {
console.log(err);
} else {
console.log(info);
}
});
Run the nodemailer using node yourFileName.js
and see the Terminal outputting a success message and your inbox having your email:
References
Safe harbor statement
The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.
This work is licensed under a Creative Commons Attribution 4.0 International License.