Why do I need a username & password to send an email to Gmail smtp server
I want to create a simple smtp proxy using node.js, which receives mails and then sends them to a custom Gmail account. But when I connect to the Gmail smtp server, I need an authentication with username & password. BUT: How should the sender know the username and password of the receiver?
Why isn´t my smtp client able to send an email to a Gmail address without such an authentication?
Have I missed something?
My code:
var tls = require("tls");
var fs = require("fs");
var o = {
cert:fs.readFileSync("/certificate.pem"),
key:fs.readFileSync("/key.pem")
};
var c = tls.connect(465,"sm开发者_如何学运维tp.gmail.com",o,function(){
c.once("data",function(d){
c.write("HELO cloudstudios.ch\r\n");
c.once("data",function(d){
c.write("MAIL FROM:<test@cloudstudios.ch>\r\n");
});
});
c.on("data",function(d){
console.log(d+"");
});
});
output:
220 mx.google.com ESMTP u14sm14212124eeh.1
250 mx.google.com at your service
530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://mail.google.com/support/bin/answer.py?answer=14257 u14sm14212124eeh.1
You're using the wrong server. smtp.gmail.com is for relaying outbound email from Gmail users, and requires them to authenticate. Inbound email to Gmail users should go via the servers specified in the MX record for gmail.com, which don't require authentication -- the highest priority such server at present is gmail-smtp-in.l.google.com, but that is liable to change at any time.
You're misunderstanding. What you do need is some valid set of credentials for the SMTP server that tells the server that you are in fact authorized to use it. Once you're authenticated and authorized, you can use the SMTP server to send email to anyone.
SMTP servers used to be completely freely available to anyone, but because of rampant abuse for sending unsolicited emails, many big SMTP servers have started admitting only registered users.
For GMail, you would supply your own account details. Or, you could just look for a different SMTP server that doesn't require authentication. Your web host would typically provide you with one.
SPAM. If anyone could post through google's mail servers without authenticating one way or another, they'd just be a (massive) spam relay.
When you authenticate to an SMTP server, you don't need the account info of the recipient, but some credentials about yourself to authorize the send/relay.
精彩评论