Sending emails from streamlit app works locally but not when deployed


I’m working on an app in which I need to send emails at intervals. I’m using python’s smtplib. When I host the app locally, I have no issues, but when it’s deployed, I run into mysterious problems: Everything seems to go smoothly - the logs say the email has sent, no exceptions, I’ve even set smtplib’s log level to debug and can see that the entire SMTP client-server communication seems to be successful - but the emails never arrive. I think I’ve controlled for all other differences: same sender/receiver, same data being sent, etc. The only difference is where it’s hosted. Here’s an example of a minimal email app that causes me issues: Run locally, I receive the emails; hosted, I do not - identical in the logs. Any ideas? This may not properly be a streamlit-responsible issue, but I wondered if anyone else has had a similar problem when using streamlit.

Thank you!

Hi @Eli_Lowry

There’s similar post on the use of smtplib for sending emails from a Streamlit app along with a solution that has a code snippet by my colleague @tonykip that you can use:

Hope this helps!

1 Like

Thank you! I had seen this post, and I don’t believe it’s relevant to the particular issue I’m having. The emails send just fine from a local instance (just not from the deployment on streamlit cloud) and this is a private mail server which doesn’t have any multifactor authentication or any such thing. All passwords etc. are set up the same locally and in the deployment. I was wondering if perhaps streamlit cloud is being blocked in some way from sending requests to send emails (although, like I said, the smtplib logs don’t suggest that). Is streamlit ever blacklisted in any way that you know of?

@dataprofessor Any thoughts or similar issues?


This article seems to help in a relevant post

Here’s the relevant post

Hope this helps

Are you getting an error message from your exception in the code?

Thank you! I tried using yagmail and ran into the very same issue.

No, no exceptions are thrown and the SMTP debug logs don’t show anything problematic either.

It seems to me that it has to do with our private mail server. My guess is that it is somehow flagging streamlit-hosted apps as insecure. I’m not sure why no errors are thrown, but seeing as how it works when deployed locally and I’ve exhausted implementation options, I think I’ll just have to either host a new mail server that I have more fine-grained control over or host my streamlit app elsewhere.

Thank you!

Thank you for providing the details of your implementation. Please let us know if you find a better solution to this as am sure somebody will ask this in future.

Mmh interesting. Might be the mail server issue as you mentioned in your recent reply.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.