Example #1
0
def send_mail(

        # report,
        text="Email Body",
        subject="Stock/Crypto Report",
        from_email=username,
        to_emails=username):
    msg = MIMEMultipart('related')
    msg['From'] = from_email
    msg['To'] = to_emails
    msg['Subject'] = subject

    msg.add_alternative(report_html, subtype='html')

    txt_part = MIMEText(text, 'plain')
    msg.attach(txt_part)

    html_part = MIMEText(
        f"""
<html>
    <head></head>
    <body>
        <h2>Your Daily Stock Report<h2>
        <p> Here is a list of some stocks that are below their 200 day moving average:</p>
        {report}
        <img src = "./Email/stock_image.png">
    </body>
</html>
            """, "html")
    msg.attach(html_part)

    msg_string = msg.as_string()

    server = smtplib.SMTP(host='smtp.gmail.com', port=587)
    server.ehlo()
    server.starttls()
    server.login(username, password)
    server.sendmail(from_email, to_emails, msg.as_string())

    server.quit()
Example #2
0
from email.mime.text import MIMEText
from email import encoders
from email.message import EmailMessage

body = ""

msg = MIMEMultipart('alternative')
msg = EmailMessage()
msg['Subject'] = ""
msg['From'] = ""
e = pd.read_excel("Emails.xlsx")
emails = e['Emails'].values
print(os.getcwd())
print(emails)
msg.set_content("")
msg.add_alternative("""\'""")
part1 = MIMEText("plain", 'utf-8')
part2 = MIMEText('', "html", 'utf-8')
encoders.encode_base64(part1)
encoders.encode_base64(part2)
msg.attach(part1)
msg.attach(part2)
part = MIMEBase("application", "octet-stream")

server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("********@gmail.com", "z------a")

for emailz in emails: