-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.py
81 lines (52 loc) · 1.51 KB
/
mailer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from marrow.mailer import Mailer, Message
mailer = Mailer(dict(
transport = dict (
use = 'smtp',
host = 'smtp.xx.com',
username = "username",
password = "password"
)
))
positiv = 0
negativ = 0
def sendMail(mail):
try:
message = Message(author="[email protected]", to=mail)
# mail subject, obviously
message.subject = "Subject"
# plain text variant:
message.plain = "Please view this mail with html enabled."
# when pressing "reply", send mail to:
message.reply = "[email protected]"
# HTML variant:
message.rich = """
<h1>Header</h1>
<p>some text</p>
"""
message.attach(name='path-to-attachment.pdf')
mailer.send(message)
print('successfull sent mail to ' + mail)
return True
except:
print('There was an error for mail ' + mail + ", skipping this.")
return False
tfile = open('contacts.csv', 'r')
# format this matching to your file
lines = tfile.readline()
mails = lines.split()
mailer.start()
for mail in mails:
#csv? remove seperator:
mail = mail.replace("'", "")
mail = mail.replace(";", "")
# call method, if true: mail successfully sent
res = sendMail(mail)
# counter
if res:
positiv += 1
else:
negativ += 1
print("____________________")
print("Positiv: " + str(positiv))
print("Negativ: " + str(negativ))
mailer.stop()