How can I retrieve mail's SMTP server from email (for example [email protected]) ?
You usually can't, given that that information is not in the email address. The (in your example) op.pl part of the address isn't enough to come up with the full smtp server address. In fact, the stmp server address could be anything else, like, e.g., mystmp.op.pl, or mail.opsmtp.pl, or whatever you like.
Edit: my fault, I didn't consider the possibility of looking for the MX server. I (erroneously) thought you wanted to get it directly from the email address.
Do as Andrew suggested, it will usually work. Mind you, you get the smtp server associated with, say, op.pl, but the user who sent the email could've used a different smtp server.
Look up the MX record for the domain part of the email address, that will give you the SMTP server for the domain. For example:
$ dig op.pl MX
; <<>> DiG 9.6.0-APPLE-P2 <<>> op.pl MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65477
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 2
;; QUESTION SECTION:
;op.pl. IN MX
;; ANSWER SECTION:
op.pl. 38667 IN MX 1 mx.poczta.onet.pl.
;; AUTHORITY SECTION:
op.pl. 38667 IN NS dns2.onet.pl.
op.pl. 38667 IN NS dns3.onet.pl.
op.pl. 38667 IN NS dns.onet.pl.
;; ADDITIONAL SECTION:
mx.poczta.onet.pl. 41544 IN A 213.180.147.146
dns3.onet.pl. 40201 IN A 213.180.147.200
;; Query time: 49 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Fri Feb 5 21:58:55 2010
;; MSG SIZE rcvd: 142
Which says that mx.poczta.onet.pl
is the mail server for op.pl
outlook uses one of two methods to auto discover your email settings. Not sure about how you can use this information programically might might help point you in the right direction.
- Autodiscover (uses an xml file hosted on an exchange server to get the settings)
You can read more about Autodiscover here:
- http://office.microsoft.com/download/afile.aspx?AssetID=AM102105061033
- http://msdn.microsoft.com/en-us/library/ee332364.aspx
- Common Settings Discover (uses an algorithm to test the most common names)
You can read more about Common Settings Discover here: