File tree Expand file tree Collapse file tree 4 files changed +68
-2
lines changed
Expand file tree Collapse file tree 4 files changed +68
-2
lines changed Original file line number Diff line number Diff line change 268268 "propagate" : True ,
269269 "formatter" : "verbose" ,
270270 }
271+
272+ EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
273+
274+ EMAIL_HOST = data ["emails" ]["EMAIL_HOST" ]
275+ EMAIL_PORT = data ["emails" ]["EMAIL_PORT" ]
276+ EMAIL_HOST_USER = data ["emails" ]["EMAIL_HOST_USER" ]
277+ EMAIL_HOST_PASSWORD = data ["emails" ]["EMAIL_HOST_PASSWORD" ]
278+ EMAIL_USE_TLS = data ["emails" ]["EMAIL_USE_TLS" ]
279+ EMAIL_USE_SSL = data ["emails" ]["EMAIL_USE_SSL" ]
280+ DEFAULT_FROM_EMAIL = data ["emails" ]["DEFAULT_FROM_EMAIL" ]
Original file line number Diff line number Diff line change 1+ from django .core import mail
2+ from django .core .mail import BadHeaderError
3+ import logging
4+ from EnigmaAutomation .settings import EMAIL_BACKEND , DEFAULT_FROM_EMAIL
5+ logger = logging .getLogger (__name__ )
6+
17def emailSES (destination , subject , body ):
2- print ("Email Sent!!!" )
8+ if destination and subject and body :
9+ with mail .get_connection (backend = EMAIL_BACKEND ) as connection :
10+ try :
11+ email = mail .EmailMessage (subject = subject , body = body ,
12+ from_email = DEFAULT_FROM_EMAIL , to = destination ,
13+ connection = connection )
14+ email .content_subtype = "html"
15+ response = email .send (fail_silently = False )
16+ if response != 1 :
17+ raise Exception ('Message not delivered. Contact Admin for more details.' )
18+ except BadHeaderError :
19+ raise Exception ("Invalid header found." )
20+ else :
21+ raise Exception ('Make sure all fields are entered and valid.' )
22+
23+ logger .info ("Email Sent!!" )
324 return True
Original file line number Diff line number Diff line change 1818 ]
1919 },
2020 "emails": {
21- "access-approve": "<access-approve-email>"
21+ "access-approve": "<access-approve-email>",
22+ "EMAIL_HOST": "<email-smtp-host>",
23+ "EMAIL_PORT": "<smtp-server-port>",
24+ "EMAIL_HOST_USER": "<smtp-server-username>",
25+ "EMAIL_HOST_PASSWORD": "<smtp-server-password>",
26+ "EMAIL_USE_TLS": true,
27+ "EMAIL_USE_SSL": false,
28+ "DEFAULT_FROM_EMAIL": "<smtp-default-mail>"
2229 },
2330 "background_task_manager": {
2431 "type": "celery",
Original file line number Diff line number Diff line change 101101 "access-approve" : {
102102 "description" : " Access approve email" ,
103103 "type" : " string"
104+ },
105+ "EMAIL_HOST" : {
106+ "description" : " The host to use for sending email." ,
107+ "type" : " string"
108+ },
109+ "EMAIL_PORT" : {
110+ "description" : " Port to use for the SMTP server." ,
111+ "type" : " string"
112+ },
113+ "EMAIL_HOST_USER" : {
114+ "description" : " Username to use for the SMTP server." ,
115+ "type" : " string"
116+ },
117+ "EMAIL_HOST_PASSWORD" : {
118+ "description" : " Password to use for the SMTP server." ,
119+ "type" : " string"
120+ },
121+ "EMAIL_USE_TLS" : {
122+ "description" : " Whether to use a TLS (secure) connection when talking to the SMTP server: port 587" ,
123+ "type" : " boolean"
124+ },
125+ "EMAIL_USE_SSL" : {
126+ "description" : " Whether to use an implicit TLS (secure) connection when talking to the SMTP server: port 465" ,
127+ "type" : " boolean"
128+ },
129+ "DEFAULT_FROM_EMAIL" : {
130+ "description" : " Default email address to use for correspondence from the site manager(s)" ,
131+ "type" : " string"
104132 }
105133 }
106134 },
You can’t perform that action at this time.
0 commit comments