I am trying to send emails from my outlook account ( office 365 email ) to myself/ to others in my organization. And from my email to my users that may or may not be on office.
I am using Nodejs and Typescript and this is all happening on the server from my own email (our organizations email). So this should require no human interaction/ the access token or whatever shouldn't expire, need manual setting but rather this should be automatic or set once.
I tried the following setup
const mailOptions = {
from: "FROM@DOMAIN.AI",
to: "TO@DOMAIN.AI",
subject: req.title,
text: req.contents,
};
const info = await transporter.sendMail(mailOptions);
export const transporter = nodemailer.createTransport({
service: "Outlook365",
auth: {
user: "FROM@DOMAIN.AI",
pass: "pass",
},
});
This is the error I am getting
[Node] error: Invalid login: 535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [VI1PR0501CA0022.eurprd05.prod.outlook.com]
This is happening on localhost while developing locally, but later I am gonna deploy this to heroku.
What I tried:
- Tried this solution and enabled Authenticated SMPT
- Tried using OAUTH and registering an azure project, but there are no resources on how to do SERVER-TO-SERVER communication instead of client to server.
What I need to happen:
I have email A in organization and we have a shared inbox B. Ideally I'd be able to send email from B to B ( when user sends us a message I want it to be received in the shared inbox)
Be able to send from B (shared inbox ) to other users outside of our organization (our apps users)
After hours of searching and reading the docs, I am unable to find whether or not this is possible. All solutions mention Azure while I don't even use Azure in my app. I just need to send emails via our business email (shared inbox email) to ourself and to our users. I don't use any of the azure services, the docs are huge and are hard to navigate so I have no idea what is happening.