Why sendgrid sending mails only in queue?

Viewed 35

I first to use sendgrid in nodejs. It is my simple sending message:

const sendgrid  = require('@sendgrid/mail')

sendgrid.setApiKey(process.env.SENDGRID_PASSWORD)
    const message = {
        from: 'feruzatamyradow@mail.ru',
        to: "rozumyratamyradow@gmail.com",
        subject: 'Hello',
        text: 'Hello',
        html: '<h1>Hello</h1>'
    }

    sendgrid.send(message)
            .then((res)=>{
                console.log("Email sent...", res);
            })
            .catch(err=>{
                console.error(err);

            })

When I run this I get this:

Email sent... [
  Response {
    statusCode: 202,
    body: '',
    headers: {
      server: 'nginx',
      date: 'Wed, 07 Sep 2022 10:00:37 GMT',
      'content-length': '0',
      connection: 'close',
      'x-message-id': 'leN_4o2nSIy9bJ8UKJ9L9A',
      'access-control-allow-origin': 'https://sendgrid.api-docs.io',
      'access-control-allow-methods': 'POST',
      'access-control-allow-headers': 'Authorization, Content-Type, On-behalf-of, x-sg-elas-acl',
      'access-control-max-age': '600',
      'x-no-cors-reason': 'https://sendgrid.com/docs/Classroom/Basics/API/cors.html',
      'strict-transport-security': 'max-age=600; includeSubDomains'
    }
  },
  ''
]

When I show this email didn't have any mail message. When I check sendgrid I see this:

enter image description here

How to fix it?

1 Answers

When you submit an email message to SendGrid, SendGrid accepts your email message and puts it in a queue, then SendGrid responds to you with an HTTP 202 response.

SendGrid continuously processes messages in the queue, doing things like rendering the templates (e.g. substitution tags, Dynamic Email Templates), checking for suppressions and unsubscribes, generate click tracking links (if enabled), and more.

Using queues is an architectural decision made to achieve maximum scale. Otherwise, SendGrid wouldn't be able to send trillions of emails.

Related