本文整理汇总了Python中flaskext.mail.Message.html方法的典型用法代码示例。如果您正苦于以下问题:Python Message.html方法的具体用法?Python Message.html怎么用?Python Message.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flaskext.mail.Message
的用法示例。
在下文中一共展示了Message.html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_jam
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def new_jam():
require_admin()
form = NewJam()
if form.validate_on_submit():
title = form.title.data
new_slug = get_slug(title)
if Jam.query.filter_by(slug = new_slug).first():
flash('A jam with a similar title already exists.')
else:
start_time = form.start_time.data
new_jam = Jam(title, get_current_user(), start_time)
new_jam.theme = form.theme.data
new_jam.end_time = start_time + timedelta(hours = form.duration.data)
new_jam.team_jam = form.team_jam.data
db.session.add(new_jam)
db.session.commit()
flash('New jam added.')
# Send out mails to all interested users.
with mail.connect() as conn:
participants = Participant.query.filter_by(receive_emails=True).all()
for participant in participants:
msg = Message("BaconGameJam: Jam \"%s\" announced" % title)
msg.html = render_template("emails/jam_announced.html", jam = new_jam, recipient = participant)
msg.recipients = [participant.email]
conn.send(msg)
flash("Email notifications have been sent.")
#return render_template("emails/jam_announced.html", jam = new_jam, recipient = get_current_user())
return redirect(new_jam.url())
return render_template('new_jam.html', form = form)
示例2: send_notify
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def send_notify(notify_type, data, status=NOT_PROCESSES):
"""
Отсылает администации уведомления о каких-либо событиях.
В админку всегда, а на почту.
"""
# пока поддреживаем только один тип нотификаций (о новых видосах)
if notify_type != 0:
raise NotImplemented(u'%s notify does not support yet')
# notice = app.connection.Notice()
# notice.update({'notice_type': notify_type, 'data': data, 'status': status})
# notice.save()
if not Message or not mail or status != NOT_PROCESSES: return
msg = Message(u'Новое видео', recipients=app.config['ADMINS'])
msg.html = u"""
<p>Пользователь %(username)s добавил новое видео по трюку %(trickname)s:</p>
<a href="%(video_url)s" target="_blank">%(video_url)s</a>
<p>Отмодерировать это дело можно в админке: <a href="%(admin_url)s" target="_blank">%(admin_url)s</a></a>
""" % {
'username' : app.db.user.find_one({"_id": data["user"]})['nick'],
'trickname' : data['trickname'],
'video_url' : data['video_url'],
'admin_url' : app.config['HOST'] + '/#admin/videos/'
}
msg.body = ""
mail.send(msg)
示例3: verify_send
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def verify_send():
if request.method == 'GET':
return redirect(url_for('index'))
username = request.form.get('username', "")
print('username = ' + username)
participant = Participant.query.filter_by(username = username).first_or_404()
if participant.is_verified:
flash("%s's account is already validated." % participant.username.capitalize())
return redirect(url_for('index'))
msg = Message("Welcome to Bacon Game Jam, " + username,
recipients=[participant.email],
sender=("bgj","[email protected]"))
msg.html = render_template("emails/verification.html",
recipient=participant)
msg.recipients = [participant.email]
mail.send(msg)
flash('Verification has been resent, check your email')
return redirect(url_for('verify_status', username=username))
示例4: register
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def register(year, eventname):
form = RegisterForm()
event = Event.query.filter_by(name=eventname, year=year).first()
if form.validate_on_submit():
participant = Participant()
form.populate_obj(participant)
participant.event_id = event.id
participant.ipaddr = request.environ["REMOTE_ADDR"]
participant.useragent = request.user_agent.string
participant.email_key = uuid4().hex
db.session.add(participant)
db.session.commit()
if not participant.email_sent:
msg = Message(subject="Geekup Confirmation", recipients=[participant.email])
msg.body = render_template("confirmemail.md", participant=participant)
msg.html = markdown(msg.body)
mail.send(msg)
participant.email_sent = True
db.session.commit()
return render_template("regsuccess.html")
else:
if request.is_xhr:
return render_template("regform.html", regform=form, ajax_re_register=True)
else:
flash("Please check your details and try again.", "error")
return eventpage(eventname, regform=form)
示例5: confirm
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def confirm(hashid):
post = JobPost.query.filter_by(hashid=hashid).first()
form = forms.ConfirmForm()
if post is None:
abort(404)
elif post.status == POSTSTATUS.REJECTED:
abort(410)
elif post.status == POSTSTATUS.DRAFT:
if post.edit_key not in session.get('userkeys', []):
abort(403)
else:
# Any other status: no confirmation required (via this handler)
return redirect(url_for('jobdetail', hashid=post.hashid), code=302)
if 'form.id' in request.form and form.validate_on_submit():
# User has accepted terms of service. Now send email and/or wait for payment
if not post.email_sent:
msg = Message(subject="Confirmation of your job listing at the HasGeek Job Board",
recipients=[post.email])
msg.body = render_template("confirm_email.md", post=post)
msg.html = markdown(msg.body)
mail.send(msg)
post.email_sent = True
post.status = POSTSTATUS.PENDING
db.session.commit()
session.get('userkeys', []).remove(post.edit_key)
session.modified = True # Since it won't detect changes to lists
session.permanent = True
return render_template('mailsent.html', post=post)
return render_template('confirm.html', post=post, form=form)
示例6: send
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def send(self):
if not self.recipients:
raise Exception("No email recipients set.")
if not self.subject:
raise Exception("No email subject set.")
if not self.content:
raise Exception("No email content set.")
if app.config["MAIL_ENABLED"]:
if not app.config["MAIL_SENDER"]:
raise Exception("No email sender set in config (MAIL_SENDER).")
with mail.connect() as connection:
for recipient in self.recipients:
msg = Message(self.subject, recipients = [recipient], sender = app.config["MAIL_SENDER"])
msg.html = self.content
connection.send(msg)
else:
print "Sending mail to: "
for p in self.recipients:
print " - " + p
print "=" * 40
print "Mail Content:"
print "=" * 40
print self.content
print "=" * 40
示例7: resetpassword
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def resetpassword():
form = PasswordResetForm()
if form.validate_on_submit():
if form.username.data:
user = Users.query.filter_by(username=form.username.data).first()
elif form.email.data:
user = Users.query.filter_by(email=form.email.data).first()
else:
flash("Username or password not in system")
if user:
if user.email:
s = URLSafeSerializer('12fe454t')
key = s.dumps([user.username, user.email])
msg = Message("Password reset", sender="[email protected]", recipients=[user.email])
msg.html = "<b>testing</b> \
#<a href='http://127.0.0.1:5000/passwordreset/" + key + "'>http://127.0.0.1:5000/passwordreset/" + key + "</a>"
mail.send(msg)
flash('Email sent to: ' + user.email)
return redirect(url_for('resetpassword'))
else:
flash('No such user')
return redirect(url_for('resetpassword'))
else:
flash('No such user')
return redirect(url_for('resetpassword'))
return render_template('general/reset_password.html', form=form)
示例8: register
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def register():
if get_current_user():
flash("You are already logged in.")
return redirect(url_for("index"))
error = None
form = ParticipantRegistration()
if form.validate_on_submit():
username = form.username.data.strip()
password = form.password.data
email = form.email.data
receive_emails = form.receive_emails.data
new_participant = Participant(username,
password,
email,
False, # no admin
False, # is verified
receive_emails)
msg = Message("Welcome to Bacon Game Jam, " + username,
recipients=[email],
sender=("bgj","[email protected]"))
msg.html = render_template("emails/verification.html",
recipient=new_participant)
msg.recipients = [new_participant.email]
mail.send(msg)
db.session.add(new_participant)
db.session.commit()
flash("Your account has been created, confirm your email to verify.")
return redirect(url_for('verify_status', username=username))
return render_template('register.html', form=form, error=error)
示例9: admin_approve
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def admin_approve(key):
if key and key in app.config['ACCESSKEY_APPROVE']:
p = Participant.query.get(request.form['id'])
if not p:
status = "No such user"
else:
if 'action.undo' in request.form:
p.approved = False
status = 'Undone!'
# Remove from MailChimp
if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
try:
mc.listUnsubscribe(
id = app.config['MAILCHIMP_LIST_ID'],
email_address = p.email,
send_goodbye = False,
send_notify = False,
)
pass
except MailChimpError, e:
status = e.msg
db.session.commit()
elif 'action.approve' in request.form:
p.approved = True
status = "Tada!"
mailsent = False
# 1. Make user account and activate it
user = makeuser(p)
user.active = True
# 2. Add to MailChimp
if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
try:
mc.listSubscribe(
id = app.config['MAILCHIMP_LIST_ID'],
email_address = p.email,
merge_vars = {'FULLNAME': p.fullname,
'JOBTITLE': p.jobtitle,
'COMPANY': p.company,
'TWITTER': p.twitter,
'PRIVATEKEY': user.privatekey,
'UID': user.uid},
double_optin = False
)
except MailChimpError, e:
status = e.msg
if e.code == 214: # Already subscribed
mailsent = True
# 3. Send notice of approval
if not mailsent:
msg = Message(subject="Your registration has been approved",
recipients = [p.email])
msg.body = render_template("approve_notice.md", p=p)
msg.html = markdown(msg.body)
with app.open_resource("static/doctypehtml5.ics") as ics:
msg.attach("doctypehtml5.ics", "text/calendar", ics.read())
mail.send(msg)
db.session.commit()
示例10: send_email_verify_link
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def send_email_verify_link(useremail):
"""
Mail a verification link to the user.
"""
msg = Message(subject="Confirm your email address",
recipients=[useremail.email])
msg.body = render_template("emailverify.md", useremail=useremail)
msg.html = markdown(msg.body)
mail.send(msg)
示例11: test_send_without_body
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def test_send_without_body(self):
msg = Message(subject="testing", recipients=["[email protected]"])
self.assertRaises(AssertionError, self.mail.send, msg)
msg.html = "<b>test</b>"
self.mail.send(msg)
示例12: send_mail
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def send_mail():
from datetime import datetime
msg = Message("Hello",
sender = ("Delai.me", "[email protected]"),
recipients=["[email protected]", '[email protected]'])
#msg.body = "testing"
msg.html = "<h1>testing</h1> <p>%s</p> " % datetime.now()
mail.send(msg)
return 'email sended'
示例13: edit_jam
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def edit_jam(jam_slug):
require_admin()
jam = Jam.query.filter_by(slug = jam_slug).first_or_404()
if not 0 <= jam.getStatus().code <= 1:
# editing only during the jam and before
flash("The jam is over, you cannot edit it anymore.")
return redirect(jam.url())
form = EditJam()
if form.validate_on_submit():
# remember what has changed
changes = {}
changes["theme"] = [jam.theme != form.theme.data, jam.theme]
changes["title"] = [jam.title != form.title.data, jam.title]
changes["start_time"] = [jam.start_time != form.start_time.data, jam.start_time]
title_changed = jam.title != form.title.data
start_time_changed = jam.start_time != form.start_time.data
# change the options
jam.theme = form.theme.data
jam.title = form.title.data
jam.start_time = form.start_time.data
db.session.commit()
changed = (changes["theme"][0] or
changes["title"][0] or
changes["start_time"][0])
if not changed:
flash("Nothing has changed. Keep moving!")
else:
# inform users about change
if form.email.data:
with mail.connect() as conn:
participants = Participant.query.filter_by(receive_emails=True).all()
for participant in participants:
msg = Message("BaconGameJam: Jam \"%s\" changed" % changes["title"][1])
msg.html = render_template("emails/jam_changed.html", jam = jam, changes = changes, recipient = participant)
msg.recipients = [participant.email]
conn.send(msg)
flash("Email notifications have been sent.")
flash("The jam has been changed.")
return redirect(jam.url())
elif request.method != "POST":
form.title.data = jam.title
form.theme.data = jam.theme
form.start_time.data = jam.start_time
return render_template('edit_jam.html', jam = jam, form = form)
示例14: approve
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def approve(key):
if key and key in app.config['ACCESSKEY_APPROVE']:
p = Participant.query.get(request.form['id'])
if not p:
status = 'No such user'
else:
if 'action.undo' in request.form:
p.approved = False
status = 'Undone!'
# Remove from MailChimp
if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
try:
mc.listUnsubscribe(
id = app.config['MAILCHIMP_LIST_ID'],
email_address = p.email,
send_goodbye = False,
send_notify = False,
)
pass
except MailChimpError, e:
status = e.msg
db.session.commit()
elif 'action.approve' in request.form:
p.approved = True
status = "Tada!"
mailsent = False
# 1. Add to MailChimp
if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
try:
mc.listSubscribe(
id = app.config['MAILCHIMP_LIST_ID'],
email_address = p.email,
merge_vars = {'FULLNAME': p.fullname,
'JOBTITLE': p.jobtitle,
'COMPANY': p.company,
'TWITTER': p.twitter},
double_optin = False
)
except MailChimpError, e:
status = e.msg
if e.code == 214: # Already subscribed
mailsent = True
# 2. Send notice of approval
if not mailsent:
msg = Message(subject="Your registration has been approved",
recipients = [p.email])
msg.body = render_template("approve_notice.md", p=p)
msg.html = markdown(msg.body)
mail.send(msg)
db.session.commit()
示例15: send_activation_email
# 需要导入模块: from flaskext.mail import Message [as 别名]
# 或者: from flaskext.mail.Message import html [as 别名]
def send_activation_email(self, view):
"""Send the e-mail that allows a user to activate their account."""
if not self.reg_code:
self._gen_reg_code()
db.session.commit()
msg = Message("Account Activation",
recipients=[self.email])
print self.reg_code
activate_url = url_for(view, user_id=self.id,
reg_code=self.reg_code, _external=True)
msg.html = render_template('email_activate.html', user=self,
activate_url=activate_url)
msg.body = render_template('email_activate.txt', user=self,
activate_url=activate_url)
mail.send(msg)