def sendLetterOrEmail(*args): if letterOrEmail.get() == "Email": # Setting to/from and subject fromaddy = "WHERE THE EMAIL WILL BE SENT FROM(EMAIL ADDRESS)" toaddy = "WHERE THE EMAIL WILL BE SENT TO(EMAIL ADDRESS)" msg = MIMEMultipart() msg["From"] = fromaddy msg["To"] = toaddy msg["Subject"] = "An email from Powerful Python" text = MIMEText("""Please see the attached PDF. Thank you for your business!""") part = MIMEBase("application", "octet-stream") with open(path, "rb") as file: part.set_payload(file.read()) encoders.encode_base64(part) part.add_header("Content-Disposition", 'attachement; filename="{}"'.format(op.basename(path))) msg.attach(part) msg.attach(text) # Mail send mailer = smtplib.SMTP("smtp.gmail.com:587") mailer.ehlo() mailer.starttls() mailer.login("INSERT LOGIN USERNAME HERE", "INSERT LOGIN PASSWORD HERE") mailer.sendmail(msg['From'], msg['To'], msg.as_string()) mailer.quit() top = Toplevel() top.title("Email Sent!") notification = Message(top, text="Email Sent!") notification.pack() else: top = Toplevel() top.title("Letter Sent!") msg = Message(top, text="Letter Sent!") msg.pack()