I was trying to implement email verification and had created a Yandex account to send emails to all clients. However, whenever I tried to send an email with the below code, I received an error:
{ [SenderError: Mail from command failed - 501 5.1.7 Bad address mailbox syntax.]
name: 'SenderError',
data: '501 5.1.7 Bad address mailbox syntax.',
stage: 'mail' }
Code:
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "Yandex",
auth: {
user: "username", // to be replaced by actual username and password
pass: "password"
}
});
//sending verification email to user
link="http://localhost:5000/verify?id="+ hashedEmail;
mailOptions={
to : req.body.email,
subject : "Please confirm your Email account",
html : "Hello,<br> Please Click on the link to verify your email.<br><ahref="+link+">Click here to verify</a>"
}
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
res.end("error");
}else{
console.log("Message sent: " + response.message);
res.end("sent");
}
});
However, the same piece of code works when service is changed from "Yandex" to "Gmail".
Is Yandex no longer supported or am I incorrectly using the service?
Also, I tried with 'mail.ee' as the service and it gives an authentication failure.
So technically, it only works with Gmail.
You do not seem to have set the from
option. Some services accept empty senders, some do not.
Thank You. That works now.
But why do we need a 'from' field if we are already setting a SMTP transport to communicate? Wouldn't that be redundant?
Also, Yandex does not show emails in the sent folder, gmail does! Is that a nodemailer issue or a service provider (i.e Yandex) issue?
Username is not automatically the sender address as username can be anything and might not be related to the account email address in any way. Some services use e-mail address as the SMTP username but some services issue random strings as usernames, so these values are not related. If you want the message to be copied to the Sent folder then you need to do this with an IMAP client. Gmail does this proactively but this is not a standard behavior and almost no other service supports it.
Most helpful comment
You do not seem to have set the
from
option. Some services accept empty senders, some do not.