I am trying to send emails with already made Zip attachments and I am running into errors with gmail's security kicking them back. Originally I was using a gmail account to send the email, but I learned that gmail blocks that. So now I am using an outlook email. It sends the emails, which is an improvement, but my recipient emails (gmail) are returning the emails. How do people get around this? Surely there has to be a way to send zip files to gmail addresses. Here is my code:
UPDATE: I opened the returned email I sent - the attached file is a .bin file, not the .zip file. I may be misunderstanding the code and converting the zip file to binary rather than just attaching it.
def send_mail(zips_folder):
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
sender_email = "senderEmail@outlook.com"
receiver_email ="receiverEmail@gmail.com"
message = MIMEMultipart()
message["From"] = sender_email
message['To'] = receiver_email
message['Subject'] = "subject"
zf = open(r"C:\Users\Full File Path to Zip File\Zip File Name.zip",'rb')
obj = MIMEBase('application', 'octet-stream')
obj.set_payload(zf.read())
encoders.encode_base64(obj)
obj.add_header('Content-Disposition', "attachment; filename= " )
message.attach(obj)
my_message = message.as_string()
email_session = smtplib.SMTP("smtp-mail.outlook.com", 587)
email_session.starttls()
email_session.login(sender_email, 'email password')
email_session.sendmail(sender_email, receiver_email, my_message)
email_session.quit()
print("YOUR MAIL HAS BEEN SENT SUCCESSFULLY")