Commit 46c9918cebdc423bad56835f6d2649dc234b3194
1 parent
652031df
Exists in
master
and in
5 other branches
smtp config
Showing
2 changed files
with
40 additions
and
1 deletions
Show diff stats
amadeus/settings.py
@@ -205,7 +205,8 @@ EMAIL_HOST = 'smtp.gmail.com' | @@ -205,7 +205,8 @@ EMAIL_HOST = 'smtp.gmail.com' | ||
205 | EMAIL_PORT = 587 | 205 | EMAIL_PORT = 587 |
206 | EMAIL_HOST_USER = 'amadeusteste@gmail.com' | 206 | EMAIL_HOST_USER = 'amadeusteste@gmail.com' |
207 | EMAIL_HOST_PASSWORD = 'amadeusteste' | 207 | EMAIL_HOST_PASSWORD = 'amadeusteste' |
208 | -EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | 208 | +# SMTP CONFIG |
209 | +# EMAIL_BACKEND = 'core.smtp.AmadeusEmailBackend' | ||
209 | 210 | ||
210 | #s3direct | 211 | #s3direct |
211 | 212 |
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +from django.core.mail.backends import EmailBackend | ||
2 | +from app.models import EmailBackend as SmtpModal | ||
3 | + | ||
4 | +class AmadeusEmailBackend(EmailBackend): | ||
5 | + """docstring for AmadeusEmailBackend""" | ||
6 | + def __init__(self, host=None, port=None, username=None, password=None, | ||
7 | + use_tls=None, fail_silently=False, use_ssl=None, timeout=None, | ||
8 | + ssl_keyfile=None, ssl_certfile=None, | ||
9 | + **kwargs): | ||
10 | + super(AmadeusEmailBackend, self).__init__(fail_silently=fail_silently) | ||
11 | + try: | ||
12 | + config = SmtpModal.objects.latest('id') | ||
13 | + self.host = config.host or settings.EMAIL_HOST | ||
14 | + self.port = config.port or settings.EMAIL_PORT | ||
15 | + self.username = config.username or settings.EMAIL_HOST_USER if username is None else username | ||
16 | + self.password = config.password or settings.EMAIL_HOST_PASSWORD if password is None else password | ||
17 | + | ||
18 | + if config.safe_conection == 2: | ||
19 | + self.use_tls = True | ||
20 | + self.use_ssl = False | ||
21 | + elif config.safe_conection == 3: | ||
22 | + self.use_tls = False | ||
23 | + self.use_ssl = True | ||
24 | + else: | ||
25 | + self.use_tls = False | ||
26 | + self.use_ssl = False | ||
27 | + | ||
28 | + self.timeout = settings.EMAIL_TIMEOUT if timeout is None else timeout | ||
29 | + self.ssl_keyfile = settings.EMAIL_SSL_KEYFILE if ssl_keyfile is None else ssl_keyfile | ||
30 | + self.ssl_certfile = settings.EMAIL_SSL_CERTFILE if ssl_certfile is None else ssl_certfile | ||
31 | + if self.use_ssl and self.use_tls: | ||
32 | + raise ValueError( | ||
33 | + "EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set " | ||
34 | + "one of those settings to True.") | ||
35 | + self.connection = None | ||
36 | + self._lock = threading.RLock() | ||
37 | + except: | ||
38 | + pass | ||
0 | \ No newline at end of file | 39 | \ No newline at end of file |