openwebwork / webwork2

Course management front end for WeBWorK
http://webwork.maa.org/wiki/Main_Page
Other
140 stars 164 forks source link

Add username and password option for SMTP authentication #2451

Open dlglin opened 1 week ago

dlglin commented 1 week ago

This adds the ability to set a username and password for authentication with the SMTP server.

It also adds the ability to set ssl_options when creating the Email::Sender::Transport::SMTP object, which is necessary if the SMTP server uses a self-signed certificate.

I have tested this with our institutional SMTP server, and with smtp.gmail.com. The only way I was able to authenticate to smtp.gmail.com was to create an app password for a gmail account that has 2FA enabled.

The gmail smtp server overwrites the "from" address in the message with the address of the user that authenticated. My smtp server will only accept messages where the "from" address in the message matches the user that authenticated, so this PR won't be very useful without some implementation of setting "reply-to" addresses on messages, as discussed in #2383. I can either add that to this PR or start a new PR for that.

drgrice1 commented 1 week ago

I tested this with a gmail account, and I can see that this works. I also see that the "from" address is filled in by the gmail smtp server with the email address of the user that authenticated. The gmail smtp server moves the original "from" address set by WeBWorK to the "X-Google-Original-From" field in the email source, but that is not shown anywhere in any email clients (including the gmail client in the browser). So I think that adding a "reply-to" implementation is certainly needed with this. If you already have that coded, then I think you should add it to this pull request.