简体   繁体   中英

ec2 node.js server not sending email - any ideas?

I have a website that I'm getting back up after a year+ of being down. I haven't made any code changes, and I've got the site back up and everything is working as before except for the site/app sending email.

It's an ubuntu node.js server. It's hosted on Amazon and I had to create another instance and repoint the dns, etc. An example code snippet that used to work but now doesn't:

var emailServer  = email.server.connect({user:"<my gmail>",password:"<mypw>",host:"smtp.gmail.com",ssl:true});
emailServer.send({
          text:    "Your username is: " + userName + ".", 
          to:      emailAddress,
          subject: "Activate Your a2zCribbage Account",
          attachment: [...]
        }, function(err, message) { if (err) console.log(err); });

When I first tried to send email the gmail account I use got a message "sign-in attempt prevented" Someone just tried to sign in to your Google Account <account> from an app that doesn't meet modern security standards.

I followed what Google said and changed the security to allow apps, but still nothing gets sent.

What am I missing? What other things can I try? Do ec2 severs not just allow email to be sent by default?

Gmail is not a platform for sending automated email. Just because you can doesn't mean it's designed for doing so.

AWS EC2 instances are also problematic for sending email ; the ports may be blocked or throttled , you are certainly getting higher spam scores for doing so.

The canonical solution is to use AWS SES . Here's sample code and here's the documentation . There's also a simple third-party library .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM