Revision 5ad78098
b/logic/amqp_connection.py | ||
---|---|---|
20 | 20 |
|
21 | 21 |
|
22 | 22 |
def send(payload, exchange, key): |
23 |
""" |
|
24 |
Send payload to the specified exchange using the provided routing key |
|
25 |
""" |
|
23 | 26 |
global _conn, _chan |
24 | 27 |
msg = amqp.Message(payload) |
25 | 28 |
msg.properties["delivery_mode"] = 2 # Persistent |
... | ... | |
35 | 38 |
_connect() |
36 | 39 |
except Exception as e: |
37 | 40 |
#self.logger.exception("Caught unexpected exception (msg: %s)", msg) |
38 |
_connect() |
|
39 |
|
|
40 | 41 |
|
41 | 42 |
def __init__(): |
42 | 43 |
_connect() |
b/logic/email.py | ||
---|---|---|
1 | 1 |
import smtplib |
2 | 2 |
import json |
3 |
import time |
|
4 |
import socket |
|
5 |
from email.mime.text import MIMEText |
|
3 |
|
|
4 |
try: |
|
5 |
from email.mime.text import MIMEText |
|
6 |
except: |
|
7 |
pass |
|
6 | 8 |
|
7 | 9 |
from django.conf import settings |
8 |
from amqplib import client_0_8 as amqp
|
|
10 |
import amqp_connection
|
|
9 | 11 |
|
10 |
def send_async(frm, to, subject, body): |
|
12 |
def send_async(frm = settings.SYSTEM_EMAIL_ADDR, |
|
13 |
to = None, subject = None, body = None): |
|
11 | 14 |
""" |
12 | 15 |
Queue a message to be sent sometime later |
13 | 16 |
by a worker process. |
... | ... | |
20 | 23 |
msg['body'] = body |
21 | 24 |
|
22 | 25 |
routekey = "logic.email.outgoing" |
26 |
amqp_connection.send(json.dumps(msg), settings.EXCHANGE_API, routekey) |
|
23 | 27 |
|
24 |
msg = amqp.Message(json.dumps(msg)) |
|
25 |
msg.properties["delivery_mode"] = 2 # Persistent |
|
26 |
|
|
27 |
conn = None |
|
28 |
while conn == None: |
|
29 |
try: |
|
30 |
conn = amqp.Connection(host=settings.RABBIT_HOST, |
|
31 |
userid=settings.RABBIT_USERNAME, |
|
32 |
password=settings.RABBIT_PASSWORD, |
|
33 |
virtual_host=settings.RABBIT_VHOST) |
|
34 |
except socket.error: |
|
35 |
time.sleep(1) |
|
36 |
|
|
37 |
chan = conn.channel() |
|
38 |
chan.basic_publish(msg,exchange=settings.EXCHANGE_EMAIL, routing_key=routekey) |
|
39 |
|
|
40 |
|
|
41 |
def send (frm, to, subject, body): |
|
28 |
def send (frm = settings.SYSTEM_EMAIL_ADDR, |
|
29 |
to = None, subject = None, body = None): |
|
42 | 30 |
""" |
43 | 31 |
Connect to the email server configured in settings.py |
44 | 32 |
and send the email. |
b/settings.py.dist | ||
---|---|---|
252 | 252 |
#SMTP server for the system |
253 | 253 |
SMTP_SERVER="127.0.0.1" |
254 | 254 |
|
255 |
#Email account to use for system emails |
|
256 |
SYSTEM_EMAIL_ADDR="noreply@grnet.gr" |
|
255 | 257 |
|
Also available in: Unified diff