'Why do emails sent from nodemailer smtp elastic fall as spam?

I have an API in nodejs where I have configured nodemailer with elastic email smtp. In elastic email I have verified the domain:

export const bookingWelcome = async (req: Request & any, res: Response) => {
    const email = req.body.email;
    const firstName = req.body.firstName;
    console.log(firstName);

    if (email && firstName) {
        const emailSender = new EmailSender();
        console.log(emailSender);
        emailSender.sendEmailProcess("WELCOME", {firstName}, email).then(() => {
            console.log(emailSender);
            return res.status(200).json({success: true});
        }).catch((error) => {
            console.log("Error sending email: ", error);
            return res.status(500).json({error: true, message: "Error sending email"});
        });
    } else {
        return res.status(400).json({error: true, message: "Email and firstName are required"});
    }
  //  console.log(res.);

    // return res.status(200).json({error: false, message: "Email sent"});
};

EmailSender.ts

const transportOptions: any = {
  transport: process.env.ELASTIC_TYPE,
    host: process.env.ELASTIC_SERVER,
    port: process.env.ELASTIC_PORT,
    auth: {
        user: process.env.ELASTIC_USER,
        pass: process.env.ELASTIC_PASS
    }
};

const EMAIL_FROM: any = process.env.emailFrom;
const BRANDING_EMAIL: any = process.env.BRANDING_EMAIL;
const BRANDING_TITLE: any = process.env.BRANDING_TITLE;

const transporter: any = nodemailer.createTransport(transportOptions);




sendEmailProcess(type: EmailTypes, data: any, to: any): Promise<any> {
    try {
      return new Promise((resolve, reject) => {
        const template = this.typesEmail(type);
        this.sendEmailFromTemplate({ to, file: template.template, subject: template.subject, data: { ...data } })
          .then((email) => {
            resolve(email);
          })
          .catch((err: Error) => {
            reject(err);
          });
      });
    } catch (err) {
      reject(err);
    }
  }
}


sendEmailFromTemplate(props: EmailModel): Promise<any> {
    return new Promise((resolve, reject) => {
      try {
        this.brandingEmail = props.brandingEmail || BRANDING_EMAIL;
        this.brandingTitle = props.brandingTitle || BRANDING_TITLE;
        this.from = props.from || this.from;
        this.to = props.to;
        this.bcc = props.bcc;
        this.subject = props.subject;
        this.attachments = props.attachments;
        this.html = props.html;
        this.text = props.text;
        this.file = props.file;
        this.data = props.data;
        this.headers = {
          "isTransactional": "true"
        };
        new Compile()
          .compile({
            file: this.file,
            data: {
              ...this.data,
              from: EMAIL_FROM,
              brandingEmail: this.brandingEmail,
              brandingTitle: this.brandingTitle,
            },
          })
          .then((compile: string) => {
            this.html = compile;
            return this.sendEmail(this);
          })
          .then((response: any) => {
            console.log(response);
            resolve(response);
          })
          .catch((err: Error & any) => {
            console.log(err);
            reject(err);
          });
      } catch (err) {
        console.log(err);
        reject(err);
      }
    });
  }




sendEmail(props: EmailModel): Promise<any> {
    return new Promise((resolve, reject) => {
      try {
        this.from = props.from || this.from;
        this.to = props.to;
        this.bcc = props.bcc;
        this.subject = props.subject;
        this.attachments = props.attachments;
        this.html = props.html;
        this.text = props.text;
        this.headers = {
          "isTransactional": "true"
        };
        transporter
          .sendMail(this)
          .then((emailResponse: any) => {
            resolve(emailResponse);
          })
          .catch((err: Error & any) => {
            reject(err);
          });
      } catch (err) {
        reject(err);
      }
    });

enter image description here

And in the email that I send I am not attaching emojis and much less links, it is pure text and images

But the emails fall into the SPAM folder, whether you send them from gmail or any other. I really do not know what to do or where to communicate so that this does not happen

Header Analyzer

enter image description here

Any advice?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source