Ejemplo n.º 1
0
def project_reg_mail(project):
    if not app.config['DEVELOPMENT']:
        sender = app.config['CONTACTS'][0]
        leader =project.student.filter(models.Student.team_leader==True).first()
        conf_email = Message("RGV RSEF - Registration",
                            sender=(sender['name'],sender['email']))
        conf_email.html = render_template('email_confirmation.html',
                                    contact=sender, leader=leader,
                                    project=project)
        conf_email.recipients = [x.email for x in leader.project.student]
        try:
            mail.send(conf_email)
            app.logger.debug("Student confirmation sent")
        except SMTPException as error:
            app.logger.warning("SMTP ERROR\n%s"%error)

        spons_email = Message("RGV RSEF - Your student has registered")
        spons_email.html = render_template('email_student_confirmation.html',
                                    contact=sender, leader=leader,
                                    project=project)
        spons_email.add_recipient(leader.sponsor.email)
        try:
            mail.send(spons_email)
            app.logger.debug("Sponsor confirmation sent")
        except SMTPException as error:
            app.logger.warning("SMTP ERROR\n%s"%error)
Ejemplo n.º 2
0
def mailer():
    form = MailForm()
    contacts = app.config["CONTACTS"]
    senders = [(x, contacts[x]["name"]) for x in range(len(contacts))]
    form.sender.choices = senders
    if form.validate_on_submit():
        if form.to.data == 1:
            queries = (Sponsor.query,)
        if form.to.data == 2:
            queries = (Student.query,)
        if form.to.data == 3:
            queries = (Sponsor.query, Student.query)
        if form.to.data == 4:
            msg = Message(
                recipients=[contacts[form.sender.data].get("email")],
                body=form.message.data,
                subject=form.subject.data,
                sender=contacts[form.sender.data].get("email"),
            )
            mail.send(msg)
            return render_template("admin/message.html", message="Mail Sent.")
        with mail.connect() as conn:
            for query in queries:
                for user in query.all():
                    msg = Message(
                        recipients=[user.email],
                        body=form.message.data,
                        subject=form.subject.data,
                        sender=contacts[form.sender.data].get("email"),
                    )
                    conn.send(msg)
        return render_template("admin/message.html", message="Mail Sent.")
    return render_template("admin/mail.html", form=form)
Ejemplo n.º 3
0
def sponsor_mail(sponsor):
    if not app.config['DEVELOPMENT']:
        sender = app.config['CONTACTS'][0]
        conf_email = Message("RGV RSEF - Sponsor Registration",
                             sender=(sender['name'],sender['email']))
        conf_email.html = render_template('email_sponsor_confirmation.html',
                                    contact=sender, sponsor=sponsor)
        conf_email.add_recipient(sponsor.email)
        mail.fail_silently = False
        try:
            mail.send(conf_email)
        except SMTPException as error:
            app.logger.warning("SMTP ERROR\n%s"%error)