Pulling MX record from DNS server

前端 未结 5 1223
既然无缘
既然无缘 2021-01-02 08:35

I am writing an application that is requiring me to do a DNS lookup for an MX record. I\'m not sure if anyone has had experience doing this kind of work but if you do, any

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 09:07

    I notice that you're writing for Linux. The idomatic way for a regular program to send mail on Unix-like systems is either:

    • Run /usr/bin/mail in a subprocess and send it the mail message on its standard input (see the mail manpage); or
    • Connect to 127.0.0.1:25 and give the local mail daemon the message to deliver.

    Both ways presume that the local mailer is configured to pass mail on to where it has to go; on a well-configured Linux box this is a fair assumption.

    If that doesn't appeal, the second-best way is for your program to accept the address of a local mail relay server to use, and just connect to that server on port 25.

    In other words, wherever possible, use an existing mail relay to send your mail on. Those mail relays will have all the local knowledge that might be necessary to get mail out of the network that you're running on - just looking up the MX and trying to send directly to the destination is not always going to work.

    If you've read all that and you still want to look up MX records, try the adns library, it takes care of all the tedious details involved in DNS resolution (and believe me, it is tedious, and easy to get wrong!).

提交回复
热议问题