-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail_response.py
More file actions
105 lines (90 loc) · 3.74 KB
/
mail_response.py
File metadata and controls
105 lines (90 loc) · 3.74 KB
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
from smtplib import SMTP_SSL
from redmail import EmailSender, gmail
import logging
from config import Config
# Todo https://stackoverflow.com/questions/13733552/logger-configuration-to-log-to-file-and-print-to-stdout
config = Config()
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=str(config.LOG_LEVEL))
log = logging.getLogger(__name__)
log.setLevel(config.LOG_LEVEL_INT)
class SendResponse:
def send_response(self,to_address, message_type, user_amount, total_amount, number_of_users):
to_emails = [to_address]
log.debug('Send Mail Respose')
with open('mail_style.css') as f:
css_content = f.readlines()
css_string = ''.join(css_content)
if message_type == 'SUCCESSFUL':
log.debug('Send SUCCESSFUL Message')
subject = 'Payment successful'
with open('success_message.html') as f:
html_content = f.readlines()
elif message_type == 'AMOUNT_TO_HIGH':
subject = 'Amount of invoice to high'
with open('amount_to_high_message.html') as f:
html_content = f.readlines()
elif message_type == 'AMOUNT_ZERO':
subject = 'Invoice amount is not set or zero'
with open('amount_zero_message.html') as f:
html_content = f.readlines()
elif message_type == 'DOMAIN_NOT_ALLOWED':
subject = 'Sorry, your domain is blacklisted!'
with open('domain_not_allowed_message.html') as f:
html_content = f.readlines()
elif message_type == 'PROVIDER_NOT_ALLOWED':
subject = 'Sorry, your mail provider is blacklisted!'
with open('provider_allowed_message.html') as f:
html_content = f.readlines()
elif message_type == 'EMAIL_NOT_VALID':
subject = 'Sorry, your e-mail address contains an alias!'
with open('email_not_valid_message.html') as f:
html_content = f.readlines()
else:
subject = 'Sorry, something went wrong!'
with open('failure_message.html') as f:
html_content = f.readlines()
html_string = ''.join(html_content)
if config.USE_GMAIL_TO_SEND_MAIL:
gmail.username = config.GMAIL_USERNAME
gmail.password = config.GOOGLE_APP_PW
gmail.send(
subject=subject,
sender=gmail.username,
receivers=to_emails,
html=html_string,
body_images={
'logo': 'f418me_200.jpg'
},
body_params={
'user_amount': user_amount,
'total_amount': total_amount,
'number_of_users': number_of_users,
'max_amount': config.MAX_AMOUNT,
'css': css_string,
}
)
else:
email = EmailSender(
host=config.MAIL_SERVER,
port=465,
cls_smtp=SMTP_SSL,
use_starttls=False,
username=config.EMAIL_ADDRESS,
password=config.EMAIL_PASSWORD
)
email.send(
subject=subject,
sender=config.EMAIL_ADDRESS,
receivers=to_emails,
html= html_string,
body_images={
'logo': 'f418me_200.jpg',
},
body_params={
'user_amount': user_amount,
'total_amount': total_amount,
'number_of_users': number_of_users,
'max_amount': config.MAX_AMOUNT,
'css': css_string,
}
)