File tree Expand file tree Collapse file tree 4 files changed +66
-2
lines changed
Expand file tree Collapse file tree 4 files changed +66
-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 = True
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+ response = mail .EmailMessage (subject = subject , body = body ,
12+ from_email = DEFAULT_FROM_EMAIL , to = destination ,
13+ connection = connection ).send (fail_silently = False )
14+ if response != 1 :
15+ raise Exception ('Message not delivered. Contact Admin for more details.' )
16+ except BadHeaderError :
17+ raise Exception ("Invalid header found." )
18+ else :
19+ raise Exception ('Make sure all fields are entered and valid.' )
20+
21+ logger .info ("Email Sent!!" )
322 return True
Original file line number Diff line number Diff line change 1717 ]
1818 },
1919 "emails": {
20- "access-approve": "<access-approve-email>"
20+ "access-approve": "<access-approve-email>",
21+ "EMAIL_HOST": "<email-smtp-host>",
22+ "EMAIL_PORT": "<smtp-server-port>",
23+ "EMAIL_HOST_USER": "<smtp-server-username>",
24+ "EMAIL_HOST_PASSWORD": "<smtp-server-password>",
25+ "EMAIL_USE_TLS": true,
26+ "EMAIL_USE_SSL": false,
27+ "DEFAULT_FROM_EMAIL": "<smtp-default-mail>"
2128 },
2229 "background_task_manager": {
2330 "type": "celery",
Original file line number Diff line number Diff line change 9696 "access-approve" : {
9797 "description" : " Access approve email" ,
9898 "type" : " string"
99+ },
100+ "EMAIL_HOST" : {
101+ "description" : " The host to use for sending email." ,
102+ "type" : " string"
103+ },
104+ "EMAIL_PORT" : {
105+ "description" : " Port to use for the SMTP server." ,
106+ "type" : " string"
107+ },
108+ "EMAIL_HOST_USER" : {
109+ "description" : " Username to use for the SMTP server." ,
110+ "type" : " string"
111+ },
112+ "EMAIL_HOST_PASSWORD" : {
113+ "description" : " Password to use for the SMTP server." ,
114+ "type" : " string"
115+ },
116+ "EMAIL_USE_TLS" : {
117+ "description" : " Whether to use a TLS (secure) connection when talking to the SMTP server: port 587" ,
118+ "type" : " boolean"
119+ },
120+ "EMAIL_USE_SSL" : {
121+ "description" : " Whether to use an implicit TLS (secure) connection when talking to the SMTP server: port 465" ,
122+ "type" : " boolean"
123+ },
124+ "DEFAULT_FROM_EMAIL" : {
125+ "description" : " Default email address to use for correspondence from the site manager(s)" ,
126+ "type" : " string"
99127 }
100128 }
101129 },
You can’t perform that action at this time.
0 commit comments