How to send emails from Microsoft Workspace Email without disabling security defaults?

I have a simple sendMail function that is supposed to send emails from my Microsoft workspace email through a Node.js backend.

async function sendMail() {
    const transporter = nodemailer.createTransport({
        host: "smtp-mail.outlook.com",
        auth: {
            user: '[email protected]',
            pass: '****',
        },
        tls: {
            ciphers: "TLSv1.2",
        },
        port: 587,
    });
    return await transporter.sendMail({
        from: '[email protected]',
        to: ['[email protected]'],
        subject: 'subject',
        text: 'Welcome aboard...!',
    });
}

However, it is erroring out with the following error: 535 5.7.139 Authentication unsuccessful, user is locked by your organization's security defaults policy. Contact your administrator.

Now, I do not want to disable security defaults. What is the best and safest way to implement this?, and is the Microsoft Graph API a viable option here?, or anything else?