fief-dev / fief

Users and authentication management SaaS
https://www.fief.dev
Other
486 stars 42 forks source link

SendEmailError on SMTP with SSL : Connection unexpectedly closed #394

Open galbini opened 1 week ago

galbini commented 1 week ago

Describe the bug

During registration of a new user, the following exception occurred:

File "/usr/local/lib/python3.12/site-packages/fief/tasks/register.py", line 33, in run self.email_provider.send_email( │ │ └ <function SMTP.send_email at 0xffff79e47600> │ └ <fief.services.email.smtp.SMTP object at 0xffff785e1dc0> └ <fief.tasks.register.OnAfterRegisterTask object at 0xffff784750a0> File "/usr/local/lib/python3.12/site-packages/fief/services/email/smtp.py", line 60, in send_email raise SendEmailError(str(e)) from e └ <class 'fief.services.email.base.SendEmailError'>

To Reproduce

Steps to reproduce the behavior:

  1. Configure Fief with SMTP with a SSL connexion ex : EMAIL_PROVIDER_PARAMS={"ssl": true, "host": "mail.infomaniak.com", "port":"465"}
  2. Go to '/register'
  3. Set form and Click on 'subcribe'
  4. See error on logs

Expected behavior

A clear and concise description of what you expected to happen.

Configuration

Additional context

My SMTP config work with https://github.com/turbodog/python-smtp-mail-sending-tester In your code, the SSL parameter seems used to configure tls but not ssl with SMTP_SSL object.

fief-bailiff[bot] commented 1 week ago

Hail, @galbini 👋 Welcome to Fief's kingdom!

Our team will get back to you very soon to help.

In the meantime, take a minute to star our repository ⭐️

star-fief

Want to support us?

Subscribe to one of our paid plan to help us continue our work and receive exclusive information and benefits! Starts at $5/month 🪙

Subscribe

Farewell!
frankie567 commented 5 days ago

Yes, our SMTP implementation doesn't support SSL encryption but rather TLS encryption. This is something that has been reported a few times (not sure if/how we should fix this).

Try with the port 587 instead of 465, that should fix the issue.

galbini commented 2 days ago

Hello, I try with port 587 but I was the next error fief.services.email.base.SendEmailError: (550, b'5.7.1 Sender mismatch')

I'm not a python expert but i found the next sample code that's works

` server = None if options.usessl: server = smtplib.SMTP_SSL(serveraddr, options.serverport) else: server = smtplib.SMTP(serveraddr, options.serverport)

server.set_debuglevel(options.debuglevel) server.connect(serveraddr, options.serverport) server.ehlo() if options.usetls: server.starttls() server.ehlo() if options.SMTP_USER != "": server.login(options.SMTP_USER, options.SMTP_PASS) server.sendmail(fromaddr, toaddr, msg) server.quit() `

frankie567 commented 2 days ago

If I understand the SMTP error 5.7.1 Sender mismatch, it means that the SMTP server rejected the From address you specified. Make sure to set the DEFAULT_FROM_EMAIL environment variable to an address authorized by your provider.

galbini commented 1 day ago

Thanks, that's work !