Using Node.js with Nodemailer and Mailgun, the sender address is displayed incorrectly. How can I set it properly? Example:
const settings = { apiSecret: process.env.NEW_KEY, domainName: process.env.NEW_DOMAIN };
const mailer = require('nodemailer').createTransport(require('mailgun-transport')(settings));
mailer.sendMail({ sender: '[email protected]', from: 'Alice <[email protected]>', to: '[email protected]', subject: 'Broadband Feedback', text: 'Greetings' });
hey, try removing the ‘sender’ field and only use ‘from’. i had a similar issue with mailgun and that cleared it up. make sure your settings/env vars are correct too.
Based on my experience, Mailgun sometimes overrides or sanitizes header fields if multiple addressing options are provided. I encountered a similar issue where I had to simplify the configuration by using only the ‘from’ field. It appears that specifying both fields can sometimes result in unexpected behavior because Mailgun prioritizes its own header rules. In my case, sticking with just ‘from’ and ensuring the domain settings are correctly configured in the environment resolved the problem.
After spending a considerable amount of time troubleshooting this issue, I found that the problem often lies in the redundancy of address headers. In my experience, Mailgun may not process both the ‘sender’ and ‘from’ fields as expected, leading to discrepancies in the final rendered sender address. Removing the ‘sender’ field entirely and ensuring that the ‘from’ field is correctly formatted solved the inconsistency. It also helped to verify that the device settings, particularly the Mailgun domain, were correctly configured and that no additional overwriting rules were in place.
hey i solved it by ditching the sender fild and using just the from. seems mailgun doesnt handle redundant fields well, so simplifying fixed it for me. make sure your env var are set properly too.
My investigations revealed that including both sender and from headers often leads Mailgun to choose the incorrect address. I encountered issues when both fields were present and eventually simplified my configuration to rely solely on the from field. This approach ensures that Mailgun applies the correct domain settings and header logic. I also verified that all environment variables were set as expected. Consistent results were obtained once I removed any redundant header definitions, ensuring that the sender information was accurately relayed.