39 lines
1021 B
Python
39 lines
1021 B
Python
#!/usr/bin/env python
|
|
|
|
import smtplib
|
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from email.mime.base import MIMEBase
|
|
from email import encoders
|
|
|
|
# Renseigner le compte Gmail et le destinataire
|
|
fromaddr = "bp6412615@gmail.com"
|
|
frompasswd = "vYqqiz-sugqo5-mywbym"
|
|
toaddr = "bruno@clicclac.info"
|
|
|
|
msg = MIMEMultipart()
|
|
msg['From'] = fromaddr
|
|
msg['To'] = toaddr
|
|
msg['Subject'] = "Test Python send email"
|
|
f = open("/home/pi/mail_template.txt")
|
|
body = f.read()
|
|
msg.attach(MIMEText(body, 'plain'))
|
|
|
|
# Renseigner la PJ
|
|
filename = "image.jpg"
|
|
attachment = open("/home/pi/image.jpg", "rb")
|
|
|
|
part = MIMEBase('application', 'octet-stream')
|
|
part.set_payload((attachment).read())
|
|
encoders.encode_base64(part)
|
|
part.add_header('Content-Disposition', "attachment; filename= %s" % filename)
|
|
msg.attach(part)
|
|
|
|
server = smtplib.SMTP('smtp.gmail.com', 587)
|
|
#server.ehlo
|
|
server.starttls()
|
|
server.login(fromaddr, frompasswd)
|
|
text = msg.as_string()
|
|
server.sendmail(fromaddr, toaddr, text)
|
|
server.quit() |