-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (57 loc) · 2.47 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import streamlit as st
import smtplib
from email.mime.text import MIMEText
import os, ssl
email_receiver = st.text_input('To')
email_cc = st.text_input('Cc')
email_bcc = st.text_input('Bcc')
subject = st.text_input('Subject')
body = st.text_area('Body')
if st.button("Send Email"):
try:
msg = MIMEText(body)
msg['From'] = '[email protected]'
msg['To'] = email_receiver
msg['Cc'] = email_cc
msg['Bcc'] = email_bcc
msg['Subject'] = subject
context = ssl.create_default_context()
server = smtplib.SMTP('mail.languagetechnology.org', 587)#, context=context)
server.set_debuglevel(1)
server.starttls(context=context)
server.login("[email protected]",os.environ.get('APP_PASSWORD') )
errs = server.sendmail("[email protected]", email_receiver, msg.as_string())
print(errs)
server.quit()
st.success('Email sent successfully! 🚀')
except Exception as e:
st.error(f"Failed to send email: {e}")
# import streamlit as st
# import yagmail
# import os
# # Set up your email configuration
# email_address = os.environ.get('APP_EMAIL') #"[email protected]" # Replace with your email address
# email_password = os.environ.get('APP_PASSWORD') #"your_password" # Replace with your email password
# st.title("Email Sender App")
# recipient_email = st.text_input("Recipient Email", "")
# subject = st.text_input("Subject", "")
# message = st.text_area("Message", "")
# if st.button("Send Email"):
# if recipient_email and subject and message:
# try:
# # Initialize yagmail SMTP client
# yag = yagmail.SMTP(email_address, email_password, host='mail.languagetechnology.org', port=587, smtp_starttls=True, smtp_ssl=False)
# # host='smtp.office365.com', port=587, smtp_starttls=True, smtp_ssl=False
# # Send the email
# yag.send(
# to=recipient_email,
# subject=subject,
# contents=message
# )
# st.success("Email sent successfully!")
# except Exception as e:
# st.error(f"An error occurred: {str(e)}")
# else:
# st.warning("Please fill in all the required fields.")
# st.write("Note: Make sure you enable 'Less secure apps' for your Gmail account if you are using Gmail. "
# "Additionally, use an 'App Password' if you have two-factor authentication enabled.")