Reputation: 5658
I have been trying to send email trough Mailtrap SMTP server but it does not send the email. I am using Nodemailer
module in NodeJS
application to send the email. The given SMTP information(Email Sending; not Email Testing) by Mailtrap is as below:
Following is the configuration set up as in the code:
const transporter = nodemailer.createTransport({
host: 'live.smtp.mailtrap.io',
port: '587',
secure: false,
requireTLS: true,
auth: {
user: 'api',
pass: '********cc8d'
}
})
const mailOptions = {
from: req.body.email,
to: '[email protected]',
subject: `Mssage from ${req.body.email}: ${req.body.subject}`,
text: req.body.message
}
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
res.send('error');
} else {
res.send('success');
}
})
I could not find out the cause behind not sending the email. Ay solution or suggestion will be highly appreciated!
Upvotes: 1
Views: 703
Reputation: 1
It's all about changing the port
Here are the Steps:
1- Ensure you specify the port as a number.
2- MailTrap provides 4 or 5 ports; try each until it works.
Upvotes: 0
Reputation: 1
The port is not a string, loose the quotation marks, then you can also interchange to know which works for you, 587 and 25 did'nt work for me, but 2525 did.
const transporter = nodemailer.createTransport({
host: 'live.smtp.mailtrap.io',
port: 587,
secure: false,
requireTLS: true,
auth: {
user: 'api',
pass: '********cc8d'
}
})
Upvotes: 0
Reputation: 1
If you have a domain registered to Mailtrap, try to put an email from you domain in "from" field of mailOptions(even thought you don't have that email) because in some cases i faced a domain validation of the email sender.
Upvotes: 0