Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to get the headers of a sent email? #1709

Open
antonioorct opened this issue Jan 11, 2025 · 3 comments
Open

Is there a way to get the headers of a sent email? #1709

antonioorct opened this issue Jan 11, 2025 · 3 comments

Comments

@antonioorct
Copy link

Searched the documentation but couldn't find anything related to it and the sendMail response doesn't contain it

const nodemailer = require("nodemailer");

const transporter = nodemailer.createTransport({
  host: "smtp.ethereal.email",
  port: 587,
  secure: false, // true for port 465, false for other ports
  auth: {
    user: "maddison53@ethereal.email",
    pass: "jn7jnAPss4f63QBp6D",
  },
});

// async..await is not allowed in global scope, must use a wrapper
async function main() {
  // send mail with defined transport object
  const info = await transporter.sendMail({
    from: '"Maddison Foo Koch 👻" <maddison53@ethereal.email>', // sender address
    to: "bar@example.com, baz@example.com", // list of receivers
    subject: "Hello ✔", // Subject line
    text: "Hello world?", // plain text body
    html: "<b>Hello world?</b>", // html body
  });

  console.log("Message sent: %s", info.messageId);
  // Message sent: <d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email>
  // Get headers here
  const headers = info.headers;
}

main().catch(console.error);
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@antonioorct
Copy link
Author

Still looking for an answer to this

@ManuelDev89
Copy link

The response of sendMail() doesn't return a headers property, but return the headers like:
{
"rejected": [],
"accepted": [],
"transp": [],
"ehlo": [
"SIZE",
"AUTH",
"ENHANCEDSTATUSCODES",
"PIPELINING",
"CHUNKING",
],
"envelopeTime": 221,
"messageTime": 1341,
"messageSize": 1102497,
"response": "250 2.0.0 OK -- someID- gsmtp",
"envelope": {
"from": "maddison53@ethereal.email",
"to": [
"bar@example.com",
"baz@example.com"
],
},
"messageId": "d786aa62-4e0a-070a-47ed-0b0666549519@ethereal.email"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants