I'm trying to send the email gmail smtp but I'm getting the error:
My email and password is correct I'm using the nodemailer for sending the mail;
var nodemailer = require('nodemailer');
// create reusable transporter object using SMTP transport
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
admin: 'myuseremail.com',
pass: 'password'
}
});
var mailOptions = {
from: 'sender address', // sender address
to: to, // list of receivers
subject: 'Password Reset', // Subject line
html: 'Your one time password is : <b>' + temporaryPassword + ' </b>' // html body
};
transporter.sendMail(mailOptions, function (error, info) {
console.log(error,info);
}
in log i'm getting the error:
{
[Error: Invalid login]
code: 'EAUTH',
response: '535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/answer/14257 k5sm20957041pdo.48 - gsmtp',
responseCode: 535
}
I try some link but that doesn't work:
https://laracasts.com/discuss/channels/general-discussion/help-email-doesnt-get-sent-with-gmail-smtp
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'user#gmail.com',
pass: 'password'
}
});
Try the above, and do the following which worked for me.
Login to https://www.google.com/settings/security/lesssecureapps and TURN ON Access for less secure apps.
I hope it will work for you too.
Thank you.
First of all, you have to enable the settings to allow less secure apps for the gmail account that you are using. Here is the link : https://myaccount.google.com/lesssecureapps
Secondly, Allow access for "Display Unlock captcha option" (Allow access to your Google account). Here is the link : https://accounts.google.com/DisplayUnlockCaptcha
https://myaccount.google.com/lesssecureapps
Click on this link, On your Less secure app access. so after that gmail will send email to your device , confirm that it is you. You are done happy coding
Google don't allow you to send direct e-mail to other's. First of all you have to create a app password .For that thing please follow below steps to get it done
Go to your manage account section.
Then click on the security link in left side.
In the signing in to the google click on app password and it will ask you to sign in again after sign in
It will ask "select app", for mail purpose "select mail" and after that select device from which you want to send mail.
After all these steps, it will generate password for that thing and insert that like this
var smtpTransport = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "example#example.com",
pass: "password"
}
That's it.
In case you're using OAuth2 and you're facing the issue above, configuring my transporter as shown below resolved my issue.
const transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: process.env.MAIL_USER,
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
refreshToken: process.env.GOOGLE_CLIENT_REFRESH_TOKEN
}
});
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'user#gmail.com',
pass: 'password'
}
});
Try this.
For me
secure:true was giving ssl errors.
I changed
secure:false as below and worked for me.
let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false, //<<here
auth: {
user: 'example#gmail.com',
pass:'your gmail pass'
}
});
let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: true,
auth: {
user: 'example#gmail.com',
pass:'your gmail pass'
}
});
Related
whenever I try to send mail using my Godaddy hosted email in nodemailer(npm package) I get this error
Error: Invalid login: 535 User noreply#squadora.com has been restricted.
{
code: 'EAUTH',
response: '535 User noreply#example.com has been restricted.',
responseCode: 535,
command: 'AUTH PLAIN'
}
here's my code
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({
service: "Godaddy",
host: "smtpout.secureserver.net",
port: 465,
auth: {
user: "noreply#example.com",
pass: "mypassword"
}
})
but when i try to send mail using below code it gives an error
I'm trying to send emails inside next.js api functions. I have the following code:
import nodemailer, { SentMessageInfo } from "nodemailer";
export default async ({ to, subject, text, html }: Props) => {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "email-smtp.us-east-1.amazonaws.com",
port: 465,
secure: true,
auth: {
user: process.env.AWS_SES_USERNAME,
pass: process.env.AWS_SES_PASSWORD,
},
});
console.log("Sending email to", to);
// send mail with defined transport object
let info: SentMessageInfo = await transporter.sendMail({
from: '"Me" <help#myemail.io>', // sender address
to,
subject,
text,
html: html,
});
console.log("Message sent: %s", info.messageId);
return info.messageId;
};
Sometimes this can take minutes to send but I have no idea why. How would one go about debugging this? Is it possible that my Amazon SES SMTP server is throttling me? I'm not even sending emails that frequently.
Trying to send email from outlook using smtp connection. But getting error as invalid login. Checked the outlook credentials and its working fine. Tried with authMethod as PLAIN.
"
var transporter = nodemailer.createTransport({
host: 'SMTP hostname',
port: 'xx',
auth: { user: 'username', pass: 'pass' },
secureConnection: false,
tls: { ciphers: 'SSLv3' }
});
"
I'm build an API with feathersjs and I need to send an email with an attachment.
The email seems to be send but I receive nothing.
In my mail.service.js
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: 'gil.felot#myaccount.com',
pass: 'MyPassWord'
}
});
// Check the connection to the service.
transporter.verify(function(error, success) {
if (error) {
console.log(error);
} else {
console.log('Server is ready to take our messages');
}
});
Then in my hook
hook => {
const file = hook.params.file;
const email = {
from: 'gil.felot#myaccount.com', // sender address
to: 'mygmailaccount#gmail.com', // list of receivers
subject: 'Test Nodemailer', // Subject line
// text: req.body.text, // plaintext body
html: '<b>Hello world 🐴</b>', // html body
attachments: [
{
filename: file.originalname,
contents: new Buffer(file.buffer, 'base64'),
encoding: 'base64'
}
]
};
return hook.app.service('mail').create(email)
.then(function (result) {
console.log('Sent email', result);
}).catch(err => {
console.log(err);
});
}
then I got
Server is ready to take our messages
Sent email
Object {from: "gil.felot#myaccount.com", to: "mygmailaccount#gmail.com", subject: "Test Nodemailer", html: "Hello world 🐴"}
I have no idea how to check where the problem come from.
I was missing the from part while creating a mail while I was able to send mail via google smtp but my own smtp was failing with the above configuration
Was working with google
var mailOptions = { to: email, subject: 'Forgot Password', html: mailData };
Working with my smtp as well:
var mailOptions = { from: 'serverName.com', to: email, subject: 'Forgot Password', html: mailData };
Consider adding name while defining nodemailer configuration as well
let transporter = nodemailer.createTransport({
name: 'example.com' // <= Add this
host: 'smtp.example.email',
port: 587,
Ok I figure it out !
I needed to add the transporter.sendMail() inside the mail.class.js to trigger this action when I call hook.app.service('mail').create(email)
Working and the attachement file that is 0 byte in the mail but the good size inside my variable.
For me this was what I realized; if the html does not have the html tags, then the email is not sent. i.e.
This template will work
<html>
<body>
Hello and welcome
</body>
</html>
This template will not work:
<body>
Hello and welcome
</body>
This is especially when sending to office365, refer to this other question here:
Nodemailer doesn't send emails to outlook.office365 accounts
I am trying to get a simple contact form up and running in node.js with sendgrid using an apikey. It's unclear where I am going wrong.
I tried the following:
1.
var options = {
auth: {
api_user: 'xjh-4XqZGH6$HLT-IEOPFG',
api_key: 'SG.xjh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake obviously, but I would like to show the structure as I am not sure whether this is correct
}
};
and
2.
var options = {
auth: {
api_user: 'xjh-4XqZGH6$HLT-IEOPFG',
api_key: 'Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake obviously, but I would like to show the structure as I am not sure whether this is correct
}
};
and
3.
var options = {
auth: {
api_user: 'apikey',
api_key: 'SG.xnh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake obviously, but I would like to show the structure as I am not sure whether this is correct
}
};
It keeps coming back with badusername / password.
It works fine with my username (api_user) and password (api_key).
Can anyone explain what I need to do?
Cheers, Mike
OK, I figured it out. You remove the api_user in this case and use the long key. E.g.
var options = {
auth: {
api_key: 'SG.xnh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake
}
};
Best, Mike
You can use SMTP and API key together:
const mailer = nodemailer.createTransport({
host: 'smtp.sendgrid.net',
port: 465,
secure: true,
auth: {
user: 'apikey',
pass: 'SG.XXXX.XXXX',
},
});
Official docs: : https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html
For anybody stumbling over this: The preferred way now seems to be to install the nodemailer-sendgrid package which allows you to set an apiKey property - see my answer here https://stackoverflow.com/a/64726992/769726