简体   繁体   English

为什么我需要用户名和密码才能将电子邮件发送到gmail smtp服务器

[英]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, wich recieves mails and then sends them to a custom gmail account. 我想使用node.js创建一个简单的smtp代理,将接收邮件,然后将其发送到自定义gmail帐户。 But when I connect to the gmail smtp server, I need an authentication with username & password. 但是,当我连接到gmail smtp服务器时,我需要使用用户名和密码进行身份验证。 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? 为什么我的smtp客户端在没有这种身份验证的情况下无法将电子邮件发送到gmail地址?

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,"smtp.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. smtp.gmail.com用于中继来自Gmail用户的出站电子邮件,并要求他们进行身份验证。 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. 给Gmail用户的入站电子邮件应通过gmail.com的MX记录中指定的服务器,这些服务器不需要身份验证-目前此类服务器的最高优先级是gmail-smtp-in.l.google.com,但随时可能更改。

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. 你做什么,需要的是告诉你实际上授权使用它的服务器的SMTP服务器证书的一些有效集。 Once you're authenticated and authorized, you can use the SMTP server to send email to anyone. 通过身份验证和授权后,即可使用SMTP服务器将电子邮件发送给任何人。

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. SMTP服务器曾经可以完全免费提供给任何人,但是由于滥用发送不请自来的电子邮件,许多大型SMTP服务器已经开始只允许注册用户使用。

For GMail, you would supply your own account details. 对于GMail,您需要提供自己的帐户详细信息。 Or, you could just look for a different SMTP server that doesn't require authentication. 或者,您可以寻找不需要身份验证的其他SMTP服务器。 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. 如果任何人都可以通过Google的邮件服务器发布而无需通过一种或另一种方式进行身份验证,那么它们将仅仅是(大量)垃圾邮件中继。

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. 在对SMTP服务器进行身份验证时,您不需要收件人的帐户信息,但是需要一些有关您自己的凭据才能授权发送/中继。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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