Email / email_sender.py
Vwadhwa02's picture
Upload 6 files
7994ba7 verified
import utils
from utils import Body
body=body=f'''Respected Ma'am/Sir,
{Body(text)}
Regards,
Vaibhav Wadhwa
9311114563
wadhwa.vaibhav11@gmail.com
p.s. I am attaching my resume for your reference.
ps: this Application is generated by an AI model, please ignore any mistakes.and to checkout my this project visit github.com/Vwadhwa02/LinkedinToEmail'''
def send_email(to, subject, body, attachment_path=None):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os
# Email configurations
from_email = "03117711721_iot@vips.edu" # Replace with your email
password = "ehdj jdgo awjc fcko" # Replace with your email password
smtp_server = "smtp.gmail.com" # Replace with your SMTP server
smtp_port = 587 # Replace with your SMTP port
# Create the email
msg = MIMEMultipart()
msg["From"] = from_email
msg["To"] = to
msg["Subject"] = subject
msg.attach(MIMEText(body, "plain"))
# Attach the file
if attachment_path:
attachment = open(attachment_path, "rb")
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header("Content-Disposition", f"attachment; filename={os.path.basename(attachment_path)}")
msg.attach(part)
# Send the email
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls()
server.login(from_email, password)
server.sendmail(from_email, to, msg.as_string())