-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_mail.py
122 lines (94 loc) · 3.51 KB
/
send_mail.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from google.appengine.api import mail
def confirm_subscription(user):
"""
Send email for subscription.
:param user: user to send email
:type user: models.User
:return: None
"""
message = mail.EmailMessage(sender="PRIMETIME4U Support <[email protected]>",
subject="PT4U: Subscription confirmed")
message.to = "{} <{}>".format(user.name, user.key.id())
message.body = """
Dear {},
You are subscribed to PRIMETIME4U and now you only have to wait the daily mail with our movie proposal.
Enjoy our service and leave us a feedback!
The PRIMETIME4U Team
""".format(user.name)
message.send()
def confirm_unsubscription(user):
"""
Send email for unsubscription.
:param user: user to send email
:type user: models.User
:return: None
"""
message = mail.EmailMessage(sender="PRIMETIME4U Support <[email protected]>",
subject="PT4U: Unsubscription confirmed")
message.to = "{} <{}>".format(user.name, user.key.id())
message.body = """
Dear {},
Thank you for using our service. You will not receive movie proposals anymore.
Let us know why you have decided to leave our service. Your feedback is important for us.
The PRIMETIME4U Team
""".format(user.name)
message.send()
def send_suggestion(user, movie):
"""
Send email form movie suggestion.
:param user: user to send email
:type user: models.User
:param movie: movie to suggest
:type movie: JSON object
:return: None
"""
message = mail.EmailMessage(sender="PRIMETIME4U Suggestion <[email protected]>",
subject="PT4U: Your daily movie proposal")
message.to = "{} <{}>".format(user.name, user.key.id())
message.body = """
Dear {},
Today we propose to you:
Title: {};
Original Title: {};
Channel: {};
Time: {}
The PRIMETIME4U Team
""".format(user.name,
movie["title"],
movie["originalTitle"] if movie["originalTitle"] is not None else movie["title"],
movie["channel"],
movie["time"])
message.send()
def send_feedback(sender):
"""
Thank the user.
:param sender: the sender to thank
:type sender: String
:return: None
"""
message = mail.EmailMessage(sender="PRIMETIME4U Support <[email protected]>",
subject="PT4U: Thanks for your feedback")
message.to = "{}".format(sender)
message.body = """
Dear {},
Thanks for your feedback, it will be helpful in order to improve your PT4U experience!
The PRIMETIME4U Team
""".format(sender)
message.send()
def forward_mail(mail_message):
"""
Forward mail received to admins.
:param mail_message: the mail message
:type mail_message: InboundEmailMessage
:return: None
"""
content_type, encoded = mail_message.bodies(content_type='text/plain').next()
body = encoded.decode()
mail.send_mail(sender="[email protected]",
to="Claudio Pastorini <[email protected]>, "
"Dorel Coman <[email protected]>, "
"Giovanni Colonna <[email protected]>, "
"Marius Ionita <[email protected]>",
subject=mail_message.subject,
body=body,
reply_to=mail_message.sender)