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: https://minimal.streamlit.app/. 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.
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:
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?
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 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.