Jump to content

Python email send help

MikeKats

Hey guys .. i want to sent an email from myself to myself with a .txt file using python .. would this code work ? 

import smtplib

file = 'C:\file.txt'

text = "example"

mail = smtplib.SMTP('smtp.exaplegmail.com',port)

mail.ehlo()

mail.starttls()

mail.login('mail','pass')

mail.attach(file)

mail.sendmail('from','to', text)

mail.close()

 

Link to comment
Share on other sites

Link to post
Share on other sites

I think it's MIMEMultuipart who has attach method, smtp does not seem to has one. So my guess would be that the above won't work and you need to build your messages witch MIMEMultipart and MIMEText, here are a loot of examples: https://docs.python.org/2/library/email-examples.html

 

What I don't quite understand is why there are from and to arguments for sendmail and you also have to apply those in headers. But I would just do as the example says, and use MIMEMultipart.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×