Spaces:
Running
Running
File size: 1,130 Bytes
32a7233 | 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 | import smtplib
from email.message import EmailMessage
import os
#### For this version the nodes used directly not by graph
smtp_server = "smtp.gmail.com" # SMTP is protcol for sending mail, use this server
smtp_port = 587
# for large scale / send many message you should use other server
def EMAIL_sender_Node(user_email,email_txt,subject,path_pdf):
APP_email = os.environ["APP_email"]
APP_password = os.environ["APP_password"]
msg = EmailMessage()
msg["Subject"] = subject
msg["From"] = APP_email
msg["To"] = user_email
msg.set_content(email_txt)
with open(path_pdf, "rb") as f:
file_data = f.read()
msg.add_attachment(file_data,
maintype="application",
subtype="pdf",
filename=path_pdf)
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.ehlo() # know server / get info
server.starttls() # start the tls (securing protocol)
server.ehlo()
server.login(APP_email, APP_password)
server.send_message(msg)
print("Email sent!")
|