Outlook mailer

Mailer Outlook Send

Code


const sendEmail = require('jwz/mailer/outlook/send');

const sender = 'sender@outlook.com';
const password = '1234'; // Please note: storing password in plain text is insecure.

const receiver = 'receiver@outlook.com';

const subject = 'Test';
const text = 'This is a test email.'; // Added some content to the body

sendEmail(sender, password, receiver, subject, text);
            

Usage

This code sends an email using the jwz/mailer/outlook/send library. The sender provides their Outlook email and password, along with the recipient's email, subject, and message body. The function sendEmail then sends the email.

Explanation

The script imports the jwz/mailer/outlook/send module to handle email sending through Outlook. It defines key parameters for sending an email and executes the send function.

  • Parameters:
    • sender: The Outlook email address of the sender.
    • password: The sender's Outlook password (should be stored securely).
    • receiver: The email address of the recipient.
    • subject: The subject line of the email.
    • text: The body text of the email.
  • Logic:
    • Imports the sendEmail function from the required module.
    • Defines the sender, recipient, subject, and body message.
    • Calls the sendEmail function with the necessary parameters.
  • Output:
    • If successful, the email is sent to the recipient.
    • If authentication fails, an error is thrown.

Security Note

Storing passwords in plain text is not secure. It is recommended to use environment variables to store credentials securely. The example above hard codes one only to keep it readable.

Sending them is handled for you. The transport sets requireTLS: true, so the connection to Outlook must be upgraded to TLS by STARTTLS before any credential is transmitted. This matters because the Outlook365 preset connects on port 587 with secure: false, which opens in cleartext; without that setting the upgrade is attempted only when the server offers it, and a server that does not would receive the password unencrypted.

A consequence worth knowing: if the connection cannot be secured, sendEmail rejects rather than sending anything. A failure to upgrade is reported, never silently downgraded.