Totalumbau: Der Mailversand ist un eine Funktion, welcher absender, Empfänger, bcc, Subject und Anhänge übergeben werden können
This commit is contained in:
parent
364d649fa2
commit
66a736e30e
1 changed files with 54 additions and 44 deletions
98
send_Mail.py
98
send_Mail.py
|
|
@ -5,54 +5,64 @@ from email.mime.base import MIMEBase
|
|||
from email import encoders
|
||||
import os
|
||||
|
||||
fromaddr = 'carsten.richter77@gmail.com'
|
||||
toaddr = 'carsten.richter77@gmail.com'
|
||||
|
||||
pfad = os.path.dirname(__file__)
|
||||
|
||||
fobj = open(pfad+"/mpg/adressen.txt")
|
||||
bcc =[]
|
||||
def Nachricht(fradress, toadress, bccs, sub, attach):
|
||||
fromaddr = fradress
|
||||
toaddr = toadress
|
||||
|
||||
|
||||
|
||||
fobj = open(pfad + "/mpg/pass.txt")
|
||||
passw = []
|
||||
for line in fobj:
|
||||
a = line.rstrip()
|
||||
passw.append(a)
|
||||
fobj.close()
|
||||
|
||||
pwd = passw[0]
|
||||
|
||||
msg = MIMEMultipart()
|
||||
|
||||
msg['From'] = fromaddr
|
||||
msg['To'] = toaddr
|
||||
msg['Subject'] = sub
|
||||
|
||||
body = 'Hello World again and again and again'
|
||||
|
||||
msg.attach(MIMEText(body, 'plain'))
|
||||
|
||||
for each in attach:
|
||||
|
||||
filename = each
|
||||
attachment = open(pfad + '/mpg/'+each, '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, bccs, text)
|
||||
server.quit()
|
||||
return
|
||||
|
||||
fradress='carsten.richter77@gmail.com'
|
||||
toadress='carsten.richter77@gmail.com'
|
||||
sub='das ist der finale Standalonetest'
|
||||
anhang = ['adressen.txt','heute.pdf']
|
||||
|
||||
fobj = open(pfad + "/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(pfad+'/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(pfad+'/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()
|
||||
|
||||
Nachricht (fradress,toadress,bcc,sub,anhang)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue