HubobelsPython/send_Mail.py
hubobel 4ea3b21b5e Passwort wird nun als 1.Eintrag in der "Adressen.txt" erwartet,
hier folgen dann Zeile für Zeile die Empfänger (BCCs)
2017-10-10 18:01:37 +02:00

56 lines
1.3 KiB
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
fromaddr = 'carsten.richter77@gmail.com'
toaddr = 'carsten.richter77@gmail.com'
fobj = open("mpg/adressen.txt")
bcc =[]
for line in fobj:
a = line.rstrip()
bcc.append(a)
fobj.close()
pwd = bcc[0]
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = 'Hello World of Python-LISTENtest'
body = 'Hello World again and again and again'
msg.attach(MIMEText(body, 'plain'))
filename = 'heute.pdf'
attachment = open('mpg/heute.pdf','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)
filename = 'morgen.pdf'
attachment = open('mpg/morgen.pdf','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.starttls()
server.login(fromaddr,pwd)
text = msg.as_string()
server.sendmail(fromaddr, bcc[1:], text)
server.quit()