Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,9 @@
|
|
10 |
# load_dotenv()
|
11 |
# genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
|
|
|
|
|
|
13 |
"""
|
14 |
If you've two-step verification enabled, your regular password won't work. Instead, generate an app-specific password:
|
15 |
|
@@ -28,6 +31,35 @@ from email.mime.text import MIMEText
|
|
28 |
|
29 |
st.title('Send Streamlit SMTP Email π π')
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
st.markdown("""
|
32 |
**Enter your email, subject, and email body then hit send to receive an email from `[email protected]`!**
|
33 |
""")
|
@@ -55,8 +87,12 @@ if st.button("Send Email"):
|
|
55 |
|
56 |
server = smtplib.SMTP('smtp.gmail.com', 587)
|
57 |
server.starttls()
|
|
|
58 |
st.write("server.login(...) :")
|
59 |
-
|
|
|
|
|
|
|
60 |
server.sendmail(email_sender, email_receiver, msg.as_string())
|
61 |
server.quit()
|
62 |
|
|
|
10 |
# load_dotenv()
|
11 |
# genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
|
13 |
+
# ZIE OOK:
|
14 |
+
# https://realpython.com/python-send-email/#adding-attachments-using-the-email-package
|
15 |
+
|
16 |
"""
|
17 |
If you've two-step verification enabled, your regular password won't work. Instead, generate an app-specific password:
|
18 |
|
|
|
31 |
|
32 |
st.title('Send Streamlit SMTP Email π π')
|
33 |
|
34 |
+
# -------------------------------------------------------------------------------------------------------------
|
35 |
+
|
36 |
+
import smtplib, ssl
|
37 |
+
|
38 |
+
port = 587 # For starttls
|
39 |
+
smtp_server = "smtp.gmail.com"
|
40 |
+
sender_email = "[email protected]"
|
41 |
+
receiver_email = "[email protected]"
|
42 |
+
password = input("Type your password and press enter:")
|
43 |
+
message = """\
|
44 |
+
Subject: Hi there
|
45 |
+
|
46 |
+
This message is sent from Python."""
|
47 |
+
|
48 |
+
context = ssl.create_default_context()
|
49 |
+
with smtplib.SMTP(smtp_server, port) as server:
|
50 |
+
server.ehlo() # Can be omitted
|
51 |
+
server.starttls(context=context)
|
52 |
+
server.ehlo() # Can be omitted
|
53 |
+
server.login(sender_email, password)
|
54 |
+
server.sendmail(sender_email, receiver_email, message)
|
55 |
+
|
56 |
+
# -------------------------------------------------------------------------------------------------------------
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
st.markdown("""
|
64 |
**Enter your email, subject, and email body then hit send to receive an email from `[email protected]`!**
|
65 |
""")
|
|
|
87 |
|
88 |
server = smtplib.SMTP('smtp.gmail.com', 587)
|
89 |
server.starttls()
|
90 |
+
|
91 |
st.write("server.login(...) :")
|
92 |
+
# https://docs.streamlit.io/deploy/streamlit-community-cloud/deploy-your-app/secrets-management
|
93 |
+
# server.login(st.secrets["email"]["gmail"], st.secrets["email"]["password"]) # ORIGINAL
|
94 |
+
server.login(st.secrets["email"]["gmail"], st.secrets["email"]["password"]) # JB
|
95 |
+
|
96 |
server.sendmail(email_sender, email_receiver, msg.as_string())
|
97 |
server.quit()
|
98 |
|