node.jsemailnpm

How can I send E-Mail Notifications in node.js


My query is simple, all of us receive many e-mail notifications and alerts every day and from various companies. I want to achieve exactly the same. I searched as much as I can, but I could only find the way to send the mail from my personal account (Gmail). But I want to use the company's account to send the mail.

If I use nodemailer, I need to use some smtp-host or some service (like Gmail), then I need to put some credentials (auth) to send.

But if I want to use the private company's account. How can I do it with that? I can't say service: "myPrivateCompany" and and assign properties to auth, it won't work, it works with Gmail, but it won't work with private company,

how can I make it work so the receiver knows which company/website or platform has sent e-mail?

I am a beginner as you know by now. Can someone also explain a bit about the 'service' and smptp-host and port?.

Here's the picture of what I have tried.enter image description here


Solution

  • Hello here are my code I use for my company:

    export const sendEmails = async () => {
      try {
        let transporter = nodemailer.createTransport({
          host: "smtp.your server",
          port: server port,
          secure: false,
          auth: {
            user: "email to used to send",
            pass: "That email password",
          },
          tls: {
            rejectUnauthorized: false,
          },
        });
    
        let info = await transporter.sendMail({
          from: "Sender email",
          to: "email to send to,
          subject: header,
          html: "message",
        });
      } catch (e) {
        throw new Error(e);
      }
    };
    

    The above is a function I use to send my email from my nodejs app.Try it am sure it will help

    You can also pass in email,message and subject for easie