Sign in to follow this  
Followers 0
Irongeek

Find MX Record for Easy Emailing

1 post in this topic

I noticed that you had to specify an SMTP server for the function that comes with Autoit (_INetSmtpMail), so I made a quick function to find the Mail Exchange for a given domain. Should work most of the time for finding a valid SMTP server for an email address:

MsgBox(0,"",GetMX("Irongeek.com"))



Func GetMX($SomeDomain)
$cmdpid = Run(@comspec & " /C nslookup -querytype=mx " & $SomeDomain, @SystemDir, @SW_HIDE,  2) 
$line = StdoutRead($cmdpid)
$f=StringInStr($line, "mail exchanger =")+16
$i=0
$l=0
while $l < $f 
        $l=StringInStr($line, @CR, 0, $i)
        $i=$i+1
WEnd
return StringMid($line, $f, $l-$f)
EndFunc

I'm use to being able to give InStr a starting point, not an occurance number. Is there a better way?

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0