1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

Add send notification email script

This commit is contained in:
xiez
2012-07-04 13:52:40 +08:00
parent df3946ee82
commit 62c8aba292
3 changed files with 47 additions and 0 deletions

6
tools/send_mail.sh.template Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/sh
export PYTHONPATH=thirdpart
export DJANGO_SETTINGS_MODULE=settings
./user_notification.py

41
tools/user_notification.py Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/python
# encoding: utf-8
import string
from django.core.mail import send_mail
from notifications.models import UserNotification
import settings
email_template = u'''${username}您好:
您有${cnt}条新消息,请点击下面的链接查看:
${msg_url}
感谢使用我们的网站!
Seafile团队
'''
subject = u'SeaCloud新消息'
url = 'http://localhost:8000/home/my/'
notifications = UserNotification.objects.all()
d = {}
for e in notifications:
if d.has_key(e.to_user):
d[e.to_user] += 1
else:
d[e.to_user] = 1
for k in d.keys():
to_user = k
cnt = d[k]
template = string.Template(email_template)
content = template.substitute(username=to_user, cnt=cnt, msg_url=url)
send_mail(subject, content, settings.DEFAULT_FROM_EMAIL, [to_user], \
fail_silently=False)