0

I'm making some researches for my final school project. And my idea is to develop an android e-mail client.

I'm testing some ideas that I've got and a problem appeared. To contact a SMTP server, to send e-mails, I need to know is (SMTP server) name and port. For example, if a users has a mail.ru account, then I need to know the SMTP server name and port for contact.

Is there any way to find that name and port programmatically?

jww
  • 97,681
  • 90
  • 411
  • 885
Nuno Batalha
  • 151
  • 2
  • 5
  • 16
  • Take a look at this related question: http://stackoverflow.com/questions/14042742/how-can-i-look-up-a-dns-mx-record-for-a-given-server-in-java – tiguchi Feb 07 '14 at 20:30
  • The server name and port are the same used to configure your outlook, android e-mail client. Check on the site which port they used with/without encryption. Btw, you'll have to check to support tls if you want to send mail to these servers. – Loïc Faure-Lacroix Feb 07 '14 at 20:32
  • 1
    You can query a huge database programatically that has this information after you either found one online or you've made one yourself. (That's what most mail clients actually do unless they just suggest `smtp.[whateverwasafterthe@]`). – zapl Feb 07 '14 at 21:02

2 Answers2

2

Normally you just have one specific SMTP server that's configured to forward your mail.

If you want to do the delivery yourself, you'll have to ask DNS for the mailhost (try dig mail.ru MX on a linux system). However, note that if you're using a dynamic IP address, the receiver will probably block you to avoid spam.

Port for mail delivery, i.e. hosts that you find querying the MX record, is always 25. If you use your providers outgoing mail server, the port might be 587 as well - ask your provider.

Guntram Blohm
  • 9,667
  • 2
  • 24
  • 31
0

Is there any way to find that name and port programmatically?

You can find the mail host's name (or names) in DNS. Query for the MX record. Once you get a mail host, you use port 25 per RFC 5321, Simple Mail Transfer Protocol. You won't need a username and password since it's the other's mail server.


If you are trying to connect to your organization's mail server so that your mail server sends the mail to the other system, then try port 465 or port 587. Use 465 first because that's SMTPS, and then try port 587 for MSA. You want SMTPS because you don't want to put your authentication credentials on the wire in the plain text.


Here's how you query for a MX record with dig(1):

$ dig gmail.com MX

; <<>> DiG 9.8.5-P1 <<>> gmail.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42931
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;gmail.com.         IN  MX

;; ANSWER SECTION:
gmail.com.      3599    IN  MX  20 alt2.gmail-smtp-in.l.google.com.
gmail.com.      3599    IN  MX  30 alt3.gmail-smtp-in.l.google.com.
gmail.com.      3599    IN  MX  10 alt1.gmail-smtp-in.l.google.com.
gmail.com.      3599    IN  MX  5 gmail-smtp-in.l.google.com.
gmail.com.      3599    IN  MX  40 alt4.gmail-smtp-in.l.google.com.

;; Query time: 23 msec
;; SERVER: 172.16.1.10#53(172.16.1.10)
;; WHEN: Fri Feb 07 22:19:33 EST 2014
;; MSG SIZE  rcvd: 150

You should include support for the STARTTLS command per RFC 3207, SMTP Service Extension for Secure SMTP over Transport Layer Security. The server will advertise it, but the client has to engage it. That is, its the client's choice.

The STARTTLS command will keep the eavesdroppers out, like the telecoms, the NSA and GHCQ. The adversaries will have to undertake active attacks, which are more easily spotted in the wild. For example, I believe the EFF runs some X509 certificate monitoring tools that could catch some of the funny business associated with active MitM attacks.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885