Send text fixers by python smtp

Asked

Viewed 25 times

0

Exists some way to send fixers .txt by python smtplib?

This is my current code:

    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(Sender, Password_SMTP)
    server.ehlo()
    body = 'Bump request was successful.'
    subject = 'Bump request was successful'

    message = 'Subject: {}\n\n{}'.format(subject, body)

    server.sendmail(Sender, Reciever, message)
    server.quit()

1 answer

0

More or less the same way, using msg.attach:

from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

msg = MIMEMultipart()
filename = "text.txt"
f = open(filename,'r')
attachment = MIMEText(f.read())
attachment.add_header('Content-Disposition', 'attachment', filename=filename)           
msg.attach(attachment)

Obs: https://www.geeksforgeeks.org/send-mail-attachment-gmail-account-using-python/

  • What would this function file in the third row?

  • Actually, there were two problems in the first answer, first I was thinking of Python2.7 which uses read, which was discontinued in Python3, which uses the open! Second, I had to create the msg, which was corrected in the answer above! Sorry I was using the smartphone and in a hurry I forgot the details.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.