Commit e8443130 by Bach Dániel

SendMailTask: random fixes

parent 186c1dc3
...@@ -212,6 +212,8 @@ firewall_settings = { ...@@ -212,6 +212,8 @@ firewall_settings = {
"dns_ttl": "300", "dns_ttl": "300",
} }
EMAIL_HOST='cronos.ik.bme.hu'
try: try:
from cloud.local_settings import * from cloud.local_settings import *
except: except:
......
...@@ -17,6 +17,7 @@ import sys ...@@ -17,6 +17,7 @@ import sys
import datetime import datetime
from django.utils.timezone import utc from django.utils.timezone import utc
from one.tasks import SendMailTask
def reload_firewall(request): def reload_firewall(request):
if request.user.is_authenticated(): if request.user.is_authenticated():
...@@ -48,9 +49,8 @@ def firewall_api(request): ...@@ -48,9 +49,8 @@ def firewall_api(request):
obj.host = models.Host.objects.get(ipv4=data["ip"]) obj.host = models.Host.objects.get(ipv4=data["ip"])
user = obj.host.owner user = obj.host.owner
lang = user.person_set.all()[0].language lang = user.person_set.all()[0].language
s = render_to_string('mails/notification-ban-now.txt', { 'user': user, 'bl': obj } ) msg = render_to_string('mails/notification-ban-now.txt', { 'user': user, 'bl': obj, 'instance:': obj.host.instance_set.get() } )
print s SendMailTask.delay(to=obj.host.owner.email, subject='[IK Cloud] %s' % obj.host.instance_set.get().name, msg=msg)
# send_mail(settings.EMAIL_SUBJECT_PREFIX + (_('New project: %s') % p.identifier), s, settings.SERVER_EMAIL, [])
except (Host.DoesNotExist, ValidationError, IntegrityError, AttributeError): except (Host.DoesNotExist, ValidationError, IntegrityError, AttributeError):
pass pass
print obj.modified_at + datetime.timedelta(minutes=5) print obj.modified_at + datetime.timedelta(minutes=5)
......
...@@ -31,12 +31,12 @@ class Job(HourlyJob): ...@@ -31,12 +31,12 @@ class Job(HourlyJob):
delete = i.time_of_delete.replace(minute=0, second=0, microsecond=0) delete = i.time_of_delete.replace(minute=0, second=0, microsecond=0)
if delete < now: if delete < now:
msg = render_to_string('mails/notification-delete-now.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-delete-now.txt', { 'user': i.owner, 'instance': i } )
SendMailTask.delay(to=i.owner.email, subject=_('Delete notification'), msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
else: else:
for t in d: for t in d:
if delete == d[t]: if delete == d[t]:
msg = render_to_string('mails/notification-delete.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-delete.txt', { 'user': i.owner, 'instance': i } )
SendMailTask.delay(to=i.owner.email, subject=_('Delete notification'), msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
# suspend # suspend
for i in Instance.objects.filter(state='ACTIVE', time_of_suspend__isnull=False): for i in Instance.objects.filter(state='ACTIVE', time_of_suspend__isnull=False):
...@@ -45,10 +45,10 @@ class Job(HourlyJob): ...@@ -45,10 +45,10 @@ class Job(HourlyJob):
if suspend < now: if suspend < now:
msg = render_to_string('mails/notification-suspend-now.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-suspend-now.txt', { 'user': i.owner, 'instance': i } )
SendMailTask.delay(to=i.owner.email, subject=_('Stop notification'), msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
i.stop() i.stop()
else: else:
for t in d: for t in d:
if suspend == d[t]: if suspend == d[t]:
msg = render_to_string('mails/notification-suspend.txt', { 'user': i.owner, 'instance': i } ) msg = render_to_string('mails/notification-suspend.txt', { 'user': i.owner, 'instance': i } )
SendMailTask.delay(to=i.owner.email, subject=_('Stop notification'), msg=msg) SendMailTask.delay(to=i.owner.email, subject='[IK Cloud] %s' % i.name, msg=msg)
...@@ -4,12 +4,13 @@ import celery ...@@ -4,12 +4,13 @@ import celery
import os import os
import sys import sys
import time import time
from django.core.mail import send_mail
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class SendMailTask(Task): class SendMailTask(Task):
def run(self, to, subject, msg): def run(self, to, subject, msg):
sender = u'cloud@ik.bme.hu' sender = u'noreply@cloud.ik.bme.hu'
print u'%s->%s [%s]' % (sender, to, subject)
logger.info("[django][one][tasks.py] %s", msg) send_mail(subject, msg, sender, [ to ], fail_silently=False)
logger.info("[django][one][tasks.py] %s->%s [%s]" % (sender, to, subject) )
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 sign in to comment