Progress Bar for command line email utility (Python)

Viewed 49

I've been developing a command line utility to send emails using the email module in python.

Everything's working fine but I really need to add a percentage based progress to show how much of the file has been uploaded, in the program. Is it possible to do so?

Given below is my code

message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = subject

filename = "~"

with open(filename, "rb") as attachment:
    part = MIMEBase("application", "octet-stream")
    part.set_payload(attachment.read())
  
encoders.encode_base64(part)

part.add_header(
    "Content-Disposition",
    "attachment; filename= %s" %file,
)

message.attach(part)
text = message.as_string()

context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
    server.login(sender_email, password)
    server.sendmail(sender_email, receiver_email, text)
    server.close()
print("Email Sent")

Are there any methods in smtplib library which would help me to do that? Thanks in advance.

0 Answers
Related