Technical help needed re authorisation methods

Discussion of general topics about Mozilla Thunderbird
Post Reply
JRG99
Posts: 4
Joined: February 27th, 2021, 7:39 am

Technical help needed re authorisation methods

Post by JRG99 »

I wonder if someone could help me. I have written a WAMP (Windows/Apache/MySQL/PHP) system for a local charity which up until recently sent emails to users using the PEAR package in a PHP script. This is now broken on the original system, and neither can I get it to work on my test system at home with my own email provider.

I use Thunderbird for my personal mail, and authorisation is set up as "Password, transmitted insecurely", with my normal username and password. I downloaded Thunderbird sources to see if I could find where this was handled in the code, but as you can imagine this is like searching for a needle in a (very large) haystack (British idiom - don't know if it's universal 8-) ).

I am asking for help from the Thunderbird experts so I can work out how to implement the various types of authorisation.

Just to be clear, I have written this system from the ground up entirely for the charity without charge (for love, if you like), using open source software, so there is no financial implication.

I am at my wit's end trying to solve this problem, and don't want to let the charity down, so I would be grateful for any help you can give.

TIA,
Jeff
User avatar
DanRaisch
Moderator
Posts: 127243
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Technical help needed re authorisation methods

Post by DanRaisch »

Under what version of Thunderbird are you running that application?
JRG99
Posts: 4
Joined: February 27th, 2021, 7:39 am

Re: Technical help needed re authorisation methods

Post by JRG99 »

Sorry if I didn't make myself clear. That application and Thunderbird are completely separate. Because I use Thunderbird as my own email client (currently running 78.7.1, about to update to 78.8.0) I was hoping to find out from the Thunderbird source how it handled SMTP authorisation so I could modify my own PHP script to match. I downloaded the sources from the nightly build.

By mimicking the way SMTP authorisation is done in Thunderbird, I should be able to get my application to send emails successfully. However I don't know where to look. Thanks for any help you can give.

PS: I used to subscribe to these forums back in 2011 with username JeffG1 and a different (long defunct) email address
User avatar
tanstaafl
Moderator
Posts: 49647
Joined: July 30th, 2003, 5:06 pm

Re: Technical help needed re authorisation methods

Post by tanstaafl »

https://github.com/PHPMailer/PHPMailer doesn't have what you want (since your goal is to modify your PHP script)? Its got integrated support for "SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over SMTPS and SMTP+STARTTLS transports".

Perhaps the source for a simpler/smaller open source email client like Mutt might be a better choice than Thunderbird. Looking at https://gitlab.com/muttmua/mutt it looks like the bulk of the smtp source is in smtp.c .

http://kb.mozillazine.org/Session_logging_for_mail/news explains how to enable logging in Thunderbird.
morat
Posts: 6435
Joined: February 3rd, 2009, 6:29 pm

Re: Technical help needed re authorisation methods

Post by morat »

Thunderbird 78 source
http://searchfox.org/comm-esr78/search?path=smtp
http://searchfox.org/comm-esr78/source/ ... ervice.idl
http://searchfox.org/comm-esr78/source/ ... Server.idl
http://searchfox.org/comm-esr78/search? ... vices.smtp
http://searchfox.org/comm-esr78/search?q=nsISmtpService
http://searchfox.org/comm-esr78/search?q=nsISmtpServer
http://searchfox.org/comm-esr78/search? ... Insecurely
http://searchfox.org/comm-esr78/source/ ... ersion.txt

Code: Select all

(function () {
  var smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"].
    getService(Components.interfaces.nsISmtpService);
  var server = smtpService.defaultServer;
  alert(MailServices.smtp); // [xpconnect wrapped nsISmtpService]
  alert(smtpService);       // [xpconnect wrapped nsISmtpService]
  alert(server);            // [xpconnect wrapped nsISmtpServer]
})();
Last edited by morat on February 27th, 2021, 6:57 pm, edited 1 time in total.
JRG99
Posts: 4
Joined: February 27th, 2021, 7:39 am

Re: Technical help needed re authorisation methods

Post by JRG99 »

Thank you so much for the help, people. I will work through the various suggestions tomorrow.
JRG99
Posts: 4
Joined: February 27th, 2021, 7:39 am

Re: Technical help needed re authorisation methods

Post by JRG99 »

After weighing up the options I decided to go the PHPMailer route. It really is a great package with built-in Debug facilities (which I've needed!). I installed Composer and used that to install PHPMailer. I've nearly got it working, but still getting errors.
I have got past the original problem I had, which was to fail to connect to the host, and am now left with the error "SMTP Error: Could not authenticate."

I have set up the host name, username and password exactly as I have in my Thunderbird client, so I think I just need another tweak to get it all working. In my Thunderbird SMTP settings I have "Port: 587", "Authentication method: Password, transmitted insecurely", and "Connection Security: None". I've not explicitly set the port, as I believe that defaults to 587, but what other settings do I need to make this equivalent to my Thunderbird client (which, it goes without saying, works perfectly)?

This is the debug output I got:

Code: Select all

2021-03-01 14:33:15 SERVER -> CLIENT: 220 mail50.extendcp.co.uk ESMTP Exim Mon, 01 Mar 2021 14:33:15 +0000
2021-03-01 14:33:15 CLIENT -> SERVER: EHLO localhost
2021-03-01 14:33:15 SERVER -> CLIENT: 250-mail50.extendcp.co.uk Hello host86-151-185-147.range86-151.btcentralplus.com [86.151.185.147]250-SIZE 31457280250-8BITMIME250-PIPELINING250-X_PIPE_CONNECT250-CHUNKING250-STARTTLS250 HELP
2021-03-01 14:33:15 CLIENT -> SERVER: STARTTLS
2021-03-01 14:33:15 SERVER -> CLIENT: 220 TLS go ahead
2021-03-01 14:33:15 CLIENT -> SERVER: EHLO localhost
2021-03-01 14:33:15 SERVER -> CLIENT: 250-mail50.extendcp.co.uk Hello host86-151-185-147.range86-151.btcentralplus.com [86.151.185.147]250-SIZE 31457280250-8BITMIME250-PIPELINING250-X_PIPE_CONNECT250-CHUNKING250 HELP
SMTP Error: Could not authenticate.
2021-03-01 14:33:15 CLIENT -> SERVER: QUIT
2021-03-01 14:33:15 SERVER -> CLIENT: 221 mail50.extendcp.co.uk closing connection
SMTP Error: Could not authenticate.
SMTP Error: Could not authenticate.
(I'm a bit concerned about the 'localhost' thing, or is this normal?)

Thanks for your continued help - it's much appreciated. Maybe @tanstaafl has the answers :)!
User avatar
tanstaafl
Moderator
Posts: 49647
Joined: July 30th, 2003, 5:06 pm

Re: Technical help needed re authorisation methods

Post by tanstaafl »

EHLO is a smtp command sent to a smtp server to start a session and have the client introduce itself.

localhost stands for your computers local tcp-ip address, not the Internet address that your PC uses to communicate with the outside world.

Looking at my smtp log I have EHLO [192.168.0.101] . That's the same address that IPCONFIG returns for my PC (i.e. localhost). Not what https://www.whatismyip.com would return as my Internet address.

I'm not sure what is causing localhost to be used in your case. I'm using a router that supports NAT, which is what I suspect is causing my copy of Thunderbird not to send a fully qualified domain name. Not sending a fully qualified domain name can cause some servers anti-spam software to increase the messages spam score. However it shouldn't cause a problem in authenticating (your current problem).

See http://kb.mozillazine.org/Replace_IP_ad ... in_headers and https://support.mozilla.org/bm/questions/989683
Post Reply