Commit e8443130 by Bach Dániel

SendMailTask: random fixes

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