C ++套接字-来自电子邮件地址的SMTP服务器主机名 [英] c++ sockets - smtp server hostname from email address

查看:311
本文介绍了C ++套接字-来自电子邮件地址的SMTP服务器主机名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有通用的解决方案可以从c / c ++中的电子邮件地址查找smtp服务器的主机名或ip?

Is there a generic solution to lookup smtp server hostname or ip from an email address in c/c++?

到目前为止,我只是在域名前面加上 smtp。,但是我不确定是否总体上可以保证?

Up to now I am just preceding the domain name by "smtp.", but I am not sure if this is guaranteed in general?

最后一件事,我仍在使用getaddrinfo来获取实际IP。它仍然是标准的吗?至少我觉得现在应该已经过时了:D。

One last thing, I am still using getaddrinfo to get to the actual IP. Is it still standard ? At least I have the feeling it should be outdated by now :D.

推荐答案


从c / c ++中的电子邮件地址查找smtp服务器主机名或ip的通用解决方案?

Is there a generic solution to lookup smtp server hostname or ip from an email address in c/c++?

不是通用解决方案,不是。尽管环顾四周,但肯定有具有该功能的第三方SMTP库可用。

Not a generic solution, no. Though there are surely 3rd party SMTP libraries available with that capability, if you look around.


到目前为止,我只是在域名前加上 smtp,但是我不确定这是否可以保证?

Up to now I am just preceding the domain name by "smtp.", but I am not sure if this is guaranteed in general?

不,不是。 proper 解决方案是提取电子邮件地址的域部分( @ 之后的所有内容),然后执行DNS查找以询问MX该域的记录。这些记录将提供域的SMTP服务器的主机名以及应使用它们的优先级顺序。然后,您可以使用其他DNS查找将那些主机名解析为IP地址,以根据需要询问A(IPv4)和AAAA(IPv6)记录。

No, it is not. The proper solution is to extract the domain portion of the email address (everything after the @), and then perform a DNS lookup asking for the MX records of that domain. Those records will provide the hostname(s) of the domain's SMTP server(s), and the priority order in which they should be used. You can then resolve those hostnames to IP addresses using additional DNS lookups asking for A (IPv4) and AAAA (IPv6) records as needed.

但是,如果您的目标是直接将电子邮件 发送到给定域的SMTP系统,不要。 正确解决方案是改为通过您自己的电子邮件提供商的SMTP服务器发送电子邮件,并根据需要将其中继到其他SMTP系统。作为一种反垃圾邮件措施,大多数SMTP服务器都不允许来自未知来源的电子邮件,仅允许来自其自己的用户的邮件,以及不允许被列入白名单以中继目的的其他已知和受信任的ISP / SMTP系统的电子邮件。

However, if your goal is to send emails directly to a given domain's SMTP system, DON'T. The correct solution is to send the emails via your own email provider's SMTP server instead, and let it relay emails to other SMTP systems as needed. As an anti-spam measure, most SMTP servers do not allow email deliveries from unknown sources, only from their own users, and from other known and trusted ISP/SMTP systems that have been whitelisted for relaying purposes.


最后一件事,我仍在使用getaddrinfo来获取实际IP。它仍然是标准吗?

One last thing, I am still using getaddrinfo to get to the actual IP. Is it still standard ?

为了将主机名解析为IP地址,是的。

For the purpose of resolving a hostname to an IP address, yes.

但是您不能使用 getaddrinfo()来检索域的SMTP主机名。您必须直接向DNS服务器查询(有很多可用的DNS库,或者您可以在自己的代码中手动实现DNS协议)。

But you cannot use getaddrinfo() to retrieve a domain's SMTP hostnames. You have to directly query a DNS server for that (there are plenty of DNS libraries available, or you can implement the DNS protocol manually in your own code).

这篇关于C ++套接字-来自电子邮件地址的SMTP服务器主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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