Commit d2292d8f authored by Georgios Gousios's avatar Georgios Gousios
Browse files

Format and send email

parent 7c3df2b2
......@@ -20,6 +20,9 @@ def _connect():
def send(payload, exchange, key):
"""
Send payload to the specified exchange using the provided routing key
"""
global _conn, _chan
msg = amqp.Message(payload)
msg.properties["delivery_mode"] = 2 # Persistent
......@@ -35,8 +38,6 @@ def send(payload, exchange, key):
_connect()
except Exception as e:
#self.logger.exception("Caught unexpected exception (msg: %s)", msg)
_connect()
def __init__():
_connect()
import smtplib
import json
import time
import socket
from email.mime.text import MIMEText
try:
from email.mime.text import MIMEText
except:
pass
from django.conf import settings
from amqplib import client_0_8 as amqp
import amqp_connection
def send_async(frm, to, subject, body):
def send_async(frm = settings.SYSTEM_EMAIL_ADDR,
to = None, subject = None, body = None):
"""
Queue a message to be sent sometime later
by a worker process.
......@@ -20,25 +23,10 @@ def send_async(frm, to, subject, body):
msg['body'] = body
routekey = "logic.email.outgoing"
amqp_connection.send(json.dumps(msg), settings.EXCHANGE_API, routekey)
msg = amqp.Message(json.dumps(msg))
msg.properties["delivery_mode"] = 2 # Persistent
conn = None
while conn == None:
try:
conn = amqp.Connection(host=settings.RABBIT_HOST,
userid=settings.RABBIT_USERNAME,
password=settings.RABBIT_PASSWORD,
virtual_host=settings.RABBIT_VHOST)
except socket.error:
time.sleep(1)
chan = conn.channel()
chan.basic_publish(msg,exchange=settings.EXCHANGE_EMAIL, routing_key=routekey)
def send (frm, to, subject, body):
def send (frm = settings.SYSTEM_EMAIL_ADDR,
to = None, subject = None, body = None):
"""
Connect to the email server configured in settings.py
and send the email.
......
......@@ -252,4 +252,6 @@ INVITATION_VALID_DAYS = 30
#SMTP server for the system
SMTP_SERVER="127.0.0.1"
#Email account to use for system emails
SYSTEM_EMAIL_ADDR="noreply@grnet.gr"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment