Sending emails from OCI with Email Delivery service in node.js


Oracle Cloud Infrastructure Email Delivery is an email sending service that provides a fast and reliable managed solution for sending high-volume emails that need to reach your recipients’ inbox. Email Delivery provides the tools necessary to send application-generated email for mission-critical communications such as receipts, fraud detection alerts, multi-factor identity verification, and password resets.

Go to a IAM/user and click on [Generate SMTP Credentials] as shown below:

Keep the credentials created in a safe place:

Create an Approved Sender (an real existing email account to put in the from field):

Grab the connection details:

Now test the code:
npm install nodemailer

Create a sendmail.js file:

var nodemailer = require('nodemailer');
async function main() {
    let testAccount = await nodemailer.createTestAccount();
    let transporter = nodemailer.createTransport({
      host: "smtp.email.eu-frankfurt-1.oci.oraclecloud.com",
      port: 25,
      secure: false,
      auth: {
        user: 'ocid1.user.oc1..aaaaaa...om', 
        pass: 'BD..._', 
      },
    });
    let info = await transporter.sendMail({
      from: '"javier...om', 
      to: "javi...om", 
      subject: "ssh access to 10.0.2.94",
      html: "<b>ssh -i deltakey -o ProxyCommand=\"ssh -i deltakey -W %h:%p -p 22 ocid1.bast...oud.com\" -p 22 opc@10.0.2.94</b>", 
    });
    console.log("Message sent: %s", info.messageId);
    console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
  }
  main().catch(console.error);

Test it:

node sendmail.js

That’s all, hope it helps! 🙂

2 Comments

  1. Abhishek

    Gives 535 error when secure is false. When secure is true, there is an error with sslv3, which also added via ttl option in nodemailer transporter.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.