简体   繁体   中英

How can I get the SMTP host name from email address?

I was working on an application which would send emails automatically at specific time intervals to a valid email. Searching through the internet I found that most of the codes use the existing email accounts such as gmail.com to send email by logging in as an SMTP client. But my problem is that I won't be knowing the smtp server name of the users email(since the user is not generally aware of these things though he will be knowing the login/passoword). For example,

someone@gmail.com should give smtp.gmail.com and port number (465)

someone@nextek.net should give mail.nextek.net and port number (?)

someone@screaming.Net smtp.tiscali.co.uk and port number (?)

I got the MX records using the domain name of the email address, but I realized that it actually gives the available incoming SMTP server names.

For example gmail.com would give gmail-smtp-in.l.google.com along with four other server name if I ping using nslookup in command prompt.

Also what is the advantage of sending email by using an existing SMTP supporting email than sending directly by looking up the email server name through dns? Or is it not possible?

Correct me if I am wrong, since I am not much familiar with the protocols.

If you're not familiar with the protocols, it doesn't make sense for you to try to implement the protocol.

Generally, an application like yours doesn't need to worry about the details of the SMTP protocol. You would use an existing SMTP client library for your platform (I'm sure there is one for .NET you can use), and connect to an MTA ( your MTA, not the recipient's), give it the email to send, and you're done. The MTA will take care of all the SMTP protocol details of figuring out how to get the email to the recipient.

Sending email is very similar to dropping a letter in the post box on the corner, and letting the post office figure out how to deliver it. You don't need to know which vehicle to put it on, or where the recipient's local post office distribution centre is, or any of those details.

You may choose to set up your own MTA using something like Postfix , or you can send email through your own Gmail account (of course you'll need a Gmail account and password before Gmail will let you do that).

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