Skip to content

Commit 58b93fe

Browse files
authored
Merge pull request #115 from browserstack/feat-email
feat: add email functionality
2 parents 2489b7d + 956610d commit 58b93fe

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

EnigmaAutomation/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,13 @@
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"]

bootprocess/general.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
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+
17
def 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

config.json.sample

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
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",

schema.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,34 @@
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
},

0 commit comments

Comments
 (0)