|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
If you've two-step verification enabled, your regular password won't work. Instead, generate an app-specific password: |
|
|
|
- Go to your Google Account. |
|
- On the left navigation panel, click on "Security." |
|
- Under "Signing in to Google," select "App Passwords." You might need to sign in again. |
|
- At the bottom, choose the app and device you want the app password for, then select "Generate." |
|
- Use this app password in your Streamlit app. |
|
|
|
""" |
|
|
|
import streamlit as st |
|
import smtplib |
|
import os |
|
from email.mime.text import MIMEText |
|
|
|
st.title('Send Streamlit SMTP Email π π') |
|
|
|
|
|
password = os.getenv("scitechtalk_gmail") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import smtplib |
|
from email.mime.text import MIMEText |
|
|
|
def send_email(subject, body, sender, recipients, password): |
|
msg = MIMEText(body) |
|
msg['Subject'] = subject |
|
msg['From'] = sender |
|
msg['To'] = ', '.join(recipients) |
|
|
|
|
|
|
|
with smtplib.SMTP_SSL('smtp.gmail.com', 25) as smtp_server: |
|
|
|
smtp_server.login(sender, password) |
|
smtp_server.sendmail(sender, recipients, msg.as_string()) |
|
|
|
print("Email sent successfully!") |
|
|
|
|
|
subject = "Test Email" |
|
body = "This is a test email sent via Python" |
|
sender = "[email protected]" |
|
|
|
|
|
recipients = ["[email protected]"] |
|
|
|
|
|
|
|
|
|
send_email(subject, body, sender, recipients, password) |
|
|
|
|
|
|
|
|
|
|
|
import smtplib, ssl |
|
|
|
port = 587 |
|
smtp_server = "smtp.gmail.com" |
|
sender_email = "[email protected]" |
|
receiver_email = "[email protected]" |
|
|
|
|
|
|
|
password = st.text_input("Type your password and press enter:") |
|
|
|
message = """\ |
|
Subject: Hi there |
|
|
|
This message is sent from Python.""" |
|
|
|
context = ssl.create_default_context() |
|
with smtplib.SMTP(smtp_server, port) as server: |
|
server.ehlo() |
|
server.starttls(context=context) |
|
server.ehlo() |
|
server.login(sender_email, password) |
|
server.sendmail(sender_email, receiver_email, message) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.markdown(""" |
|
**Enter your email, subject, and email body then hit send to receive an email from `[email protected]`!** |
|
""") |
|
|
|
|
|
email_sender = st.text_input('From', '[email protected]', disabled=True) |
|
|
|
email_receiver = "[email protected]" |
|
subject = st.text_input('Subject') |
|
body = st.text_area('Body') |
|
|
|
|
|
|
|
|
|
password = os.getenv("scitechtalk_gmail") |
|
|
|
st.write("password:", password) |
|
|
|
if st.button("Send Email"): |
|
try: |
|
msg = MIMEText(body) |
|
msg['From'] = email_sender |
|
msg['To'] = email_receiver |
|
msg['Subject'] = subject |
|
|
|
server = smtplib.SMTP('smtp.gmail.com', 587) |
|
server.starttls() |
|
|
|
st.write("server.login(...) :") |
|
|
|
|
|
server.login(st.secrets["email"]["gmail"], st.secrets["email"]["password"]) |
|
|
|
server.sendmail(email_sender, email_receiver, msg.as_string()) |
|
server.quit() |
|
|
|
st.success('Email sent successfully! π') |
|
except Exception as e: |
|
st.error(f"Failed to send email: {e}") |