Spaces:
Runtime error
Runtime error
| import smtplib | |
| from email.mime.multipart import MIMEMultipart | |
| from email.mime.base import MIMEBase | |
| from email import encoders | |
| def send_email(pdf_path, to_email): | |
| from_email = "your_email@example.com" | |
| subject = "Quote Invoice" | |
| body = "Please find attached the quote invoice." | |
| # Create the email message | |
| msg = MIMEMultipart() | |
| msg['From'] = from_email | |
| msg['To'] = to_email | |
| msg['Subject'] = subject | |
| msg.attach(MIMEText(body, 'plain')) | |
| # Attach the PDF | |
| attachment = open(pdf_path, "rb") | |
| part = MIMEBase('application', 'octet-stream') | |
| part.set_payload(attachment.read()) | |
| encoders.encode_base64(part) | |
| part.add_header('Content-Disposition', f"attachment; filename={pdf_path.split('/')[-1]}") | |
| msg.attach(part) | |
| # Send the email via SMTP | |
| server = smtplib.SMTP('smtp.gmail.com', 587) | |
| server.starttls() | |
| server.login(from_email, "your_email_password") | |
| server.sendmail(from_email, to_email, msg.as_string()) | |
| server.quit() | |