Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set custom certificate for Email server (Proton Mail) #200

Open
sonn-gamm opened this issue Sep 20, 2023 · 2 comments
Open

Set custom certificate for Email server (Proton Mail) #200

sonn-gamm opened this issue Sep 20, 2023 · 2 comments

Comments

@sonn-gamm
Copy link

Hi!

I need to use ProtonMail for a project and have gone through the process to learn how to set the integration up. Proton requires to run a local software called ProtonMail Bridge, that acts as a kind of self-hosted email server between Proton's servers and your machine.

Somehow using STARTTLS did not work, I tried all sort of config for FastAPI-Mail without luck. It always ended failing by giving the following error message:

smtplib [SSL: WRONG_VERSION_NUMBER]

Therefore I tried to use a TLS connection instead, and found you can force ProtonMail Bridge to use TLS if you want. You need to you export a cert.pem file to use as context for your email SSL script.

See for example:

import smtplib
import ssl

bridge_certificate="/path/tp/cert.pem"

sslctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
sslctx.options &= ~ssl.OP_NO_SSLv3
sslctx.load_verify_locations(cafile=bridge_certificate)
sslctx.verify_mode = ssl.CERT_OPTIONAL
sslctx.check_hostname = False

sender = <proton-email>
receiver = <test-email>

smtp = smtplib.SMTP('127.0.0.1', 1025) # 1025 - port from proton mail bridge info
smtp.starttls(context=sslctx)
smtp.login(sender, password)

msg = """\
Subject: Hi there

This message is sent from Python."""
smtp.sendmail(sender, [receiver], msg)

Is there any way to tell FastAPI-Mail to use a custom certificate for the connection?

Thanks.

@sonn-gamm
Copy link
Author

I made a patch for this, it seems to be working sonn-gamm@fbd7709

I'll make a PR soon.

@sabuhish
Copy link
Owner

Thanks for the patch!! We will make your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants