本文整理汇总了Python中mailer.Mailer.send_mail方法的典型用法代码示例。如果您正苦于以下问题:Python Mailer.send_mail方法的具体用法?Python Mailer.send_mail怎么用?Python Mailer.send_mail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mailer.Mailer
的用法示例。
在下文中一共展示了Mailer.send_mail方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_send_mail__unencrypted_authorized
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def test_send_mail__unencrypted_authorized(self, smtp_mock):
mail_data = MailData()
mail_data.recipients = ["[email protected]"]
mail_data.subject = "Test mail"
mail_data.body = "Test body"
mailer_config = MailerConfig()
mailer_config.smtp_host = "localhost"
mailer_config.smtp_port = 25
mailer_config.use_starttls = False
mailer_config.use_ssl = False
mailer_config.user = "Tester"
mailer_config.password = "Secret"
mailer_config.sender = "[email protected]"
mailer = Mailer()
mail = mailer.create_mail(mail_data)
mailer.send_mail(mailer_config, mail)
assert smtp_mock.call_count == 1
assert smtp_mock.call_args == ((mailer_config.smtp_host, mailer_config.smtp_port),)
assert smtp_mock.return_value.starttls.call_count == 0
assert smtp_mock.return_value.login.call_count == 1
assert smtp_mock.return_value.login.call_args == ((mailer_config.user, mailer_config.password),)
assert smtp_mock.return_value.sendmail.call_count == 1
assert smtp_mock.return_value.sendmail.call_args == ((mail["From"], mail["To"], mail.as_string()),)
assert smtp_mock.return_value.quit.call_count == 1
示例2: add_training
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def add_training(self, t_day, t_time, t_instructor):
t = Training(day = t_day, time = t_time, instructor = t_instructor)
self.response.write("""
<p>
<b>Treino adicionado:</b><br/>
<b>Dia:</b> %s - %s <br/>
<b>Instrutor:</b> %s
</p>
""" %(t.day, t.time, t.instructor))
t.put()
Mailer.send_mail(self, "[email protected]", "Novo treino", "Novo treino cadastrado:\n\tDia: %s - %s\n\tProfessor: %s" %(t_day, t_time, t_instructor))
示例3: add_user
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def add_user(self, u_name, u_type):
u = User(name = u_name, type = u_type)
self.response.write("""
<p>
<b>Usuario adicionado:</b><br/>
<b>Nome: </b> %s <br/>
<b>Tipo: </b> %s
</p>
""" %(u.name, u.type))
u.put()
Mailer.send_mail(self, "[email protected]", "Novo usuario", "Novo usuario cadastrado:\n\tNome: %s\n\tTipo: %s" %(u_name, u_type))
示例4: course_added
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def course_added(sender, instance, action, *args, **kwargs):
if action == 'post_add':
category = instance.name
courses = instance.courses.all()
latest = courses.reverse()[0]
mailer = Mailer()
for course in courses:
students = course.student_set.all()
for s in students:
name = "%s %s" % (s.first_name, s.last_names)
text = u"""
Estimado %s
Ha sido creado el curso %s bajo la categoria %s, podria ser de su interes.
""" % (name, latest, category)
mail = s.email
mailer.send_mail(name, mail, u'Curso agregado', text)
示例5: guide_updated
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def guide_updated(sender, instance, created, *args, **kwargs):
if not created:
course = instance.guide.course
course_name = course.name
guide_name = instance.guide.name
theme = instance.title
students = course.student_set.all()
mailer = Mailer()
for s in students:
name = "%s %s" % (s.first_name, s.last_names)
text = u"""
Estimado %s
Le informamos que el contenido del tema %s de la guia %s del curso %s, ha sido actualizado.
""" % (name, theme, guide_name, course_name)
mail = s.email
mailer.send_mail(name, mail, u'Contenido Actualizado', text)
示例6: get
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def get(self):
Library.get_books(self)
#1. URL_fetch====================================================
Register.register(self)
self.response.set_status(200)
self.response.write("App no Ar - Solicitacao Recebida<br/>")
#2. E-mail=======================================================
user_address = "[email protected]"
subject = "Solicitacao via Middleware"
body = "Igor, alguém acessou sua aplicação. Vá conferir se ninguém zuou tudo!"
Mailer.send_mail(self, user_address, subject, body)
示例7: session_ended
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def session_ended(sender, instance, created, *args, **kwargs):
if not created and instance.ended and not instance.mail_sent:
students = instance.course.student_set.all()
content = ", ".join(t.title for t in instance.themes.all())
mailer = Mailer()
for s in students:
name = "%s %s" % (s.first_name, s.last_names)
text = u"""
Estimado/a %s
Su clase ha finalizado, el contenido visto fue:
%s
Se le recomienda ampliamente revisar el contenido.
""" % (name, content)
mail = s.email
mailer.send_mail(name, mail, u"Contenidos de la clase de hoy", text)
instance.mail_sent = True
instance.save()
示例8: mail
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
def mail(self, sender, content):
smtp_server = {'host': celery.conf.get('MAIL_SMTP_SERVER'),
'port': celery.conf.get('MAIL_SMTP_PORT'),
'user': celery.conf.get('MAIL_SMTP_USER'),
'passwd': celery.conf.get('MAIL_SMTP_PASSWORD'),
'ssl': celery.conf.get('MAIL_SMTP_SSL')}
mailer = Mailer()
try:
mailer.send_mail(
smtp_server,
celery.conf.get('MAIL_FROM_ADDRESS'),
sender,
celery.conf.get('MAIL_SUBJECT'),
content,
)
except MailerException, e:
logging.warning(e)
try:
self.retry()
except MaxRetriesExceededError:
""" 重试次数超过后依然失败的处理 """
pass
示例9: Mailer
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
client = Mailer()
d = {}
sections = Section.objects.filter(course__school="jhu")
for section in sections:
if not section.was_full and (section.size <= section.enrolment):
section.was_full = True
section.save()
try:
timetables = PersonalTimetable.objects.filter(sections__id__contains=section.id, semester=semester)
except:
print("Problem with getting section with id = " + str(section.id))
for student, timetable in zip(map(lambda t: t.student, timetables), timetables):
if timetable != student.personaltimetable_set.filter(semester=semester).order_by('last_updated').last():
# Only applies for the student's last modified schedule.
continue
# NOTIFIY STUDENT
if student not in d:
d[student] = []
d[student].append(section)
elif section.was_full and section.enrolment < section.size:
section.was_full = False
section.save()
for student, sections in d.items():
client.send_mail(student, "Course Waitlist Notification from Semester.ly", "email_waitlist.html", {'sections': sections})
client.cleanup()
示例10: len
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
import django, os, json
import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "semesterly.settings")
django.setup()
from student.models import *
from timetable.models import Semester
from mailer import Mailer
if len(sys.argv) < 4:
print("Please specify a school, a term (e.g. Fall), and a year (e.g. 2017).")
exit(0)
school = sys.argv[1]
term = sys.argv[2]
year = int(sys.argv[3])
semester = Semester.objects.filter(name=term, year=year)
students = PersonalTimetable.objects.filter(school=school, semester=semester).values_list("student", flat=True).distinct()
client = Mailer()
for student_id in students:
student = Student.objects.get(id=student_id)
if not student.emails_enabled or not student.user.email or student.class_year < 2018:
continue
client.send_mail(student, "Registration Starts Tomorrow", "email_registration_deadline.html", {'freshman': student.class_year == 2020,
'sophomore': student.class_year == 2019, 'junior': student.class_year == 2018})
client.cleanup()
示例11: Mailer
# 需要导入模块: from mailer import Mailer [as 别名]
# 或者: from mailer.Mailer import send_mail [as 别名]
client = Mailer()
students = PersonalTimetable.objects.filter(school=school, semester=semester).values_list("student", flat=True).distinct()
for student_id in students:
student = Student.objects.get(id=student_id)
if not student.emails_enabled or not student.user.email:
continue
tt = student.personaltimetable_set.filter(semester=semester).order_by('last_updated').last()
textbook_json = map(lambda c:
{
"textbooks": map(lambda t: model_to_dict(Textbook.objects.get(isbn=t)), tt.sections.filter(~Q(textbooks=None), course=c).values_list("textbooks", flat=True).distinct()),
"course_name": c.name,
"course_code": c.code,
}, tt.courses.all())
# Go through textbooks. If all empty lists (no textbooks), go to next student.
have_textbooks = False
for dic in textbook_json:
if dic["textbooks"]:
have_textbooks = True
break
if not have_textbooks:
continue
client.send_mail(student, "Happy First Day of Classes - Textbooks from Semester.ly", "email_textbooks.html", {'textbooks_json': textbook_json})
client.cleanup()