Well, the title might be a bit misleading, but I couldn't find a better way to describe my question. I tried to set up my machine to send email via the php mail() function. It turns out I can't. My ISP is blocking port 25, so no luck there. Then, out of curiosity, I set up Thunderbird with a gmail account, and sent a message to a hotmail account. This worked. I was curious as to how Thunderbird manages to send the emails.

I saw in the configuration of the gmail account on Thunderbird that it is using a different port, not 25. Thunderbird seems to set this values automatically, which is pretty nice. A while back I wanted to set up an account on Thunderbird, and I had to manually input the SMTP server values, and the IMAP/POP3 values, so it is nice to see that they do it automatically now.

I also checked the mail logs, and nothing had changed. I guess this is a no brainer, since the email is not being sent by postfix's sendmail, but by gmail. Is that right?

Well, my question is how does Thunderbird manages to send email? and more importantly, can I do something similar to be able to send email from my php scripts?

I realize this might be a "stupid" question, but I really know nothing about this matter.

And since I'm already asking, where can I learn about this? Do they teach it in school? Maybe to computer scientists? What is a good book to get started on this nice world of email, SMTP, POP3, and stuff.

  • If you are using gmails SMTP server or one of an ISP or a web host, then you will almost certainly need to use SSL and authenticate the smtp session. This should help: stackoverflow.com/questions/3618712/… – Paul Apr 19 '12 at 12:38
  • Thank you Paul. I was able to solve the problem. I used my websites SMTP server, I detail the process here: imbuzu.wordpress.com/2012/04/19/… – Buzu Apr 21 '12 at 4:00
  • Hi Buzu, if you have found the answer to your question yourself, please add an answer below and accept it. – Paul Apr 21 '12 at 13:02

To send an e-mail your mail client (either Thunderbird or your PHP script) must connect to a SMTP server that can relay the e-mail across the internet to finally reach the recipients e-mail server. The standard port for SMTP is 25, but other ports such as 587 or 465 can sometimes be used instead, often with some kind of encryption such as SSL.

Which port and encryption to use depends on the SMTP server you are using. Thunderbird, as you've mentioned, can detect this by trying out common ports and protocols. To send e-mail via SSL from a PHP script you can for example use the PEAR Mail extension.

Information on how the e-mail protocols work should probably not be considered common knowledge. Wikipedia of course has an overview, but as you say a book is probably recommended if you want to dig deeper.

| improve this answer | |
  • I know about the client having to connect to an SMTP server, just because I've been fighting with this for a few hours now, but this info you are telling me is very useful. – Buzu Apr 19 '12 at 6:31
  • I just telnet to an SMTP server on port 587. It seems this port is open. Maybe I should try setting postfix to use this port. Also, will try the PEAR Mail extension. Thanks a lot for the info. It is very useful. For now I'm reading postfix.org/BASIC_CONFIGURATION_README.html#myorigin to get my feet wet on this interesting world. – Buzu Apr 19 '12 at 6:33

I know you solved this, but this is an answer to the original question: how does thunderbird send mail?

The Thunderbird client is bundled with connection info for a few known mail providers, including (as you've seen) gmail, hotmail, yahoo, and probably a few others. The config would know:

  • Protocol for incoming - POP3 or IMAP (sadly, Thunderbird can't do Exchange: Microsoft only licensed Exchange protocol for mobile devices)
  • Protocol for outgoing - pretty much universally SMTP
  • Ports for where the services are.
  • Do I need to authenticate to SMTP server? (SMTP servers usually need authentication now, or else you'll supply more spam)
  • Encryption? TLS/SSL? or does it support STARTTLS?

So, when you created your account, you told Thunderbird "me@gmail.com". It saw it was gmail.com, and used what config knew about the account (IMAP/SSL on imap.gmail.com, SMTP/SSL on smtp.gmail.com, etc.)

When you send a mail, Thunderbird knows it needs to log into the SMTP server, turn on encryption, and then send the message with a very specific format.

As far as learning, check the RFCS, they're the last word in what travels over the wires. Also, check the docs for postfix, and sendmail, and other MTAs (Mail Transfer Agents).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.