CodeBuddyAI / agent /tools /email.py
TahaFawzyElshrif
uploaded files
32a7233
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!")