JBHF commited on
Commit
d179ce0
verified
1 Parent(s): 0332308

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py 07-04-2024
2
+ # https://discuss.streamlit.io/t/send-email-with-smtp-and-gmail-address/48145
3
+ # https://github.com/tonykipkemboi/streamlit-smtp-test
4
+ # streamlit-smtp-test/streamlit_app.py at main 路 tonykipkemboi/streamlit-smtp-test
5
+ # https://github.com/tonykipkemboi/streamlit-smtp-test/blob/main/streamlit_app.
6
+ #
7
+ # SENT EMAILS TO: [email protected]
8
+
9
+ """
10
+ If you've two-step verification enabled, your regular password won't work. Instead, generate an app-specific password:
11
+
12
+ - Go to your Google Account.
13
+ - On the left navigation panel, click on "Security."
14
+ - Under "Signing in to Google," select "App Passwords." You might need to sign in again.
15
+ - At the bottom, choose the app and device you want the app password for, then select "Generate."
16
+ - Use this app password in your Streamlit app.
17
+
18
+ """
19
+
20
+ import streamlit as st
21
+ import smtplib
22
+ from email.mime.text import MIMEText
23
+
24
+ st.title('Send Streamlit SMTP Email 馃拰 馃殌')
25
+
26
+ st.markdown("""
27
+ **Enter your email, subject, and email body then hit send to receive an email from `[email protected]`!**
28
+ """)
29
+
30
+ # Taking inputs
31
+ email_sender = st.text_input('From', '[email protected]', disabled=True)
32
+ # email_receiver = st.text_input('To') # ORIGINAL
33
+ email_receiver = "[email protected]" # st.text_input('To') # JB
34
+ subject = st.text_input('Subject')
35
+ body = st.text_area('Body')
36
+
37
+ # Hide the password input
38
+ password = st.text_input('Password', type="password", disabled=True)
39
+
40
+ if st.button("Send Email"):
41
+ try:
42
+ msg = MIMEText(body)
43
+ msg['From'] = email_sender
44
+ msg['To'] = email_receiver
45
+ msg['Subject'] = subject
46
+
47
+ server = smtplib.SMTP('smtp.gmail.com', 587)
48
+ server.starttls()
49
+ server.login(st.secrets["email"]["gmail"], st.secrets["email"]["password"])
50
+ server.sendmail(email_sender, email_receiver, msg.as_string())
51
+ server.quit()
52
+
53
+ st.success('Email sent successfully! 馃殌')
54
+ except Exception as e:
55
+ st.error(f"Failed to send email: {e}")