是否可以从MX查找中获取端口? [英] Is it possible to get a port from MX lookup?

查看:93
本文介绍了是否可以从MX查找中获取端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在了解什么是通过Python代码发送电子邮件的正确方法。不过,我在了解MX查找方面有所进步: 知识之岛越大,奇迹之海岸线越长

I am on a journey of understanding what is the proper way to send an email from Python code. I have somewhat progressed in understanding of MX lookup, though: "the larger the island of knowledge, the longer the shoreline of wonder".

感谢此答案,我就可以发送电子邮件了(发送到一次性邮箱),带有以下代码段:

Thanks to this answer, I was able to send an email (to a disposable mailbox though), with this code-snippet:

import smtplib

from email.message import EmailMessage

message = EmailMessage()
message.set_content('Content of the message here.')
message['Subject'] = 'Mail sent from code'
message['From'] = 'whoever@whatever.com'
message['To'] = 'aloun36zmzazyxd3tyop@3mail.rocks'

smtplib.SMTP('mail.3mail.rocks:2525')
smtp_server.send_message(message)
smtp_server.quit()

这是我想出SMTP地址和端口的方式( mail.3mail.rocks:2525 ):

Here is how I come up with SMTP address and port (mail.3mail.rocks:2525):


  1. 3mail.rocks 域的MX查找完成:


  • host -t mx 3mail.rocks

3mail.rocks mail is handled by 10 mail.3mail.rocks.


然后我刚刚开始检查<一个href = https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol#Ports rel = nofollow noreferrer>默认使用的端口,并带有 telnet mail.3mail.rocks xxx ,这给了我以下结果:

Then I just started checking ports used by default, with telnet mail.3mail.rocks xxx, this gave me the following results:


  • telnet mail.3mail .rocks 25

Trying 89.38.99.80...
telnet: connect to address 89.38.99.80: Connection refused
telnet: Unable to connect to remote host


  • telnet mail.3mail.rocks 465

    Trying 89.38.99.80...
    telnet: connect to address 89.38.99.80: Operation timed out
    telnet: Unable to connect to remote host
    


  • telnet mail.3mail.rocks 587

    Trying 89.38.99.80...
    telnet: connect to address 89.38.99.80: Operation timed out
    telnet: Unable to connect to remote host
    


  • telnet mail.3mail.rocks 2525

    Trying 89.38.99.80...
    Connected to mail.3mail.rocks.
    Escape character is '^]'.
    220 node1 ESMTP Haraka 2.8.16 ready
    


  • 所以,这就是我找出所需端口的方式(本质上是通过蛮力)。

    So, that is how I figured out the needed port (by brute-force, essentially).

    我按照相同的步骤,在另一个一次性邮件服务( mailforspam.com )上测试了我的代码段- MX查找( host -t mx mailforspam.com )返回:

    I went on to test my snippet on another disposable mail service (mailforspam.com), following the same steps — MX lookup (host -t mx mailforspam.com) returned:

    mailforspam.com mail is handled by 10 mail2.mailforspam.com.
    mailforspam.com mail is handled by 10 mail1.mailforspam.com.
    

    尽管我无法通过telnet连接(我已经尝试了两个服务器 mail2.mailforspam.com mail1.mailforspam.com )到任何默认端口:端口 25 连接被拒绝,端口 2525 587 465 操作超时

    Though I was not able to connect via telnet (I have tried both servers mail2.mailforspam.com and mail1.mailforspam.com) to any of the default ports: port 25Connection refused, ports 2525, 587, 465Operation timed out.

    问题分别是:


    1. 我如何找出服务器代表特定域(由MX返回的域)接收邮件的正确端口抬头)?我在这里的理解是 默认端口只是约定,实际上,服务器可以使用他们选择的任何可用端口。

    2. 我假设在发送电子邮件时从一个电子邮件提供者发送到另一个电子邮件提供者,它所提交的SMTP服务器(属于正在发送电子邮件的用户)执行类似的操作(即MX查找=>与邮件接收服务器的连接=>提交电子邮件)。这样的 真实世界服务器如何确定正确的端口(或者它们只是通过默认端口强行强制使用)?

    1. How do I figure out the proper ports for the server accepting mails on behalf of a particular domain (one that is returned by MX lookup)? My understanding here is that "default" ports are just conventions, and, in fact, servers can use any free port they choose.
    2. I assume that when email is sent from one email provider to another, the SMTP server it is submitted to (one belonging to the user that is sending email) does something similar (i.e. MX lookup => connection to mail accepting server => submitting an email). How do such "real-world" servers figure out the proper port (or they just brute-forcing through the default ones)?


    推荐答案


    我如何确定服务器代表特定域(MX返回的一个域)接收邮件的正确端口查找)?

    How do I figure out the proper ports for the server accepting mails on behalf of a particular domain (one that is returned by MX lookup)?

    您在问题中显示的内容或多或少是正确的。您可能想以其他顺序尝试端口。另外,端口 2525 不是我所知道的任何标准的官方端口,但似乎是绕过阻止提交端口的防火墙的约定587

    What you've shown in your question is more or less correct. You may want to try the ports in a different order. Also, port 2525 is not an official port from any standard I'm aware of but seems to be a convention for bypassing firewalls that block the submission port 587.

    需要注意的一件事是接受邮件实际上不是一件事。有执行提交的邮件用户代理和进行传输的邮件传输代理。 提交和传输通常位于不同的端口上,这说明了您所看到的一些多样性。确定您要提交还是进行传输,然后选择适当的端口组。

    One thing to note is that "accepting mail" is not actually one thing. There are "mail user agents" that do "submission" and "mail transfer agents" that do "transfer". "Submission" and "transfer" often live on different ports which explains some of the diversity you've seen. Figure out whether you're doing submission or transfer and select the appropriate group of ports.


    我的理解是,默认端口是只是惯例,事实上,服务器可以使用他们选择的任何免费端口。

    My understanding here is that "default" ports are just conventions, and, in fact, servers can use any free port they choose.

    这不是真的,至少不是这样如果服务器希望任何人都能找到它们,因为...

    This isn't really true, at least not if the servers want anyone to be able to find them, because ...


    这种真实服务器如何找出正确的端口(或者它们只是强制使用默认端口)?

    How do such "real-world" servers figure out the proper port (or they just brute-forcing through the default ones)?

    实际上希望能够接收邮件的邮件服务器必须在标准端口号上运行。对于MTA,这意味着端口 25 可能会回退到 465 (尽管这也没有标准化)。对于MUA而言,这意味着端口 587 可能会回退到 2525 (也未标准化,但显然通常用作解决方法

    Mail servers that actually want to be able to receive mail must run on a standard port number. For MTAs this means port 25 with maybe a fallback to 465 (though this isn't standardized either). For MUAs this means port 587 with maybe a fallback to 2525 (also not standardized but apparently in common use as a workaround to MUAs being blocked).

    特别是,MX记录不包含端口信息,也不包含与SMTP相关的任何其他DNS记录类型。

    In particular, MX records carry no port information, nor does any other DNS record type related to SMTP.

    这篇关于是否可以从MX查找中获取端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆