Android: Check if SMTP server is up and running
I'm developing a small app for Android, which monitors the availability of servers and t开发者_高级运维heir services on my network.
So far I have implemented ping and HTTP(S) checks. I'd also like to monitor some mail servers. I know about libs like javamail-android, but I don't need to really send a mail. I'm looking for a simple solution (ideally without an additional lib) to connect to my MTAs and to check whether they respond correctly.
What is the best way to check the availability of mail servers on Android?
Open a socket to port 25 (smtp, no ssl) and see if you get a 220 prompt like this conversation (on a command shell):
$ telnet lilly 25
Trying lilly...
Connected to lilly.
Escape character is '^]'.
220 lilly ESMTP Postfix
noop
250 2.0.0 Ok
quit
221 2.0.0 Bye
Connection closed by foreign host.
You may also check how long the individual steps (connect until 220 , noop , quit) are taking and react on slow response times.
精彩评论