本文整理汇总了Python中flaskext.mail.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
if request.json:
try:
email = request.json['email']
except IndexError, e:
return self.send_400("%s is required" % e)
try:
user = User.select(User.q.email==email)[0]
except:
return self.send_200({"success": True})
token = ResetToken(user=user)
msg = Message("Password Reset",
sender=(SITE_NAME, "[email protected]%s" % SITE_URL),
recipients=[email])
message = """
Hello!
You (hopefully) have requested a password reset for your account at
{site_name}. In order to complete this reset, please visit:
{site_url}/reset/?{enc_token}
"""
msg.body = message.format(site_name=SITE_NAME, site_url=SITE_URL,
enc_token=quote(token.token))
g.mail.send(msg)
示例2: send_test_email
def send_test_email(recipient):
mail = Mail(app)
msg = Message("Test Message -- Candidates Emailer app",
[recipient],
sender="[email protected]")
msg.body = "This is a test message from the Candidates Emailer App"
mail.send(msg)
示例3: admin_send_reminder
def admin_send_reminder(payment_id):
payment = BankPayment.query.get_or_404(payment_id)
form = SendReminderForm()
if form.validate_on_submit():
if form.remind.data:
app.logger.info("%s sending reminder email to %s <%s> for payment %s",
current_user.name, payment.user.name, payment.user.email, payment.id)
if payment.reminder_sent:
app.logger.error('Reminder for payment %s already sent', payment.id)
flash("Cannot send duplicate reminder email for payment %s" % payment.id)
return redirect(url_for('admin_expiring'))
msg = Message("Electromagnetic Field ticket purchase update",
sender=app.config['TICKETS_EMAIL'],
recipients=[payment.user.email])
msg.body = render_template("tickets-reminder.txt", payment=payment)
mail.send(msg)
payment.reminder_sent = True
db.session.commit()
flash("Reminder email for payment %s sent" % payment.id)
return redirect(url_for('admin_expiring'))
return render_template('admin/payment-send-reminder.html', payment=payment, form=form)
示例4: admin_txn_reconcile
def admin_txn_reconcile(txn_id, payment_id):
txn = BankTransaction.query.get_or_404(txn_id)
payment = BankPayment.query.get_or_404(payment_id)
form = ManualReconcilePaymentForm()
if form.validate_on_submit():
if form.reconcile.data:
app.logger.info("%s manually reconciling against payment %s (%s) by %s",
current_user.name, payment.id, payment.bankref, payment.user.email)
if txn.payment:
app.logger.error("Transaction already reconciled")
flash("Transaction %s already reconciled" % txn.id)
return redirect(url_for('admin_txns'))
if payment.state == 'paid':
app.logger.error("Payment has already been paid")
flash("Payment %s already paid" % payment.id)
return redirect(url_for('admin_txns'))
txn.payment = payment
payment.paid()
db.session.commit()
msg = Message("Electromagnetic Field ticket purchase update",
sender=app.config['TICKETS_EMAIL'],
recipients=[payment.user.email])
msg.body = render_template("tickets-paid-email-banktransfer.txt",
user=payment.user, payment=payment)
mail.send(msg)
flash("Payment ID %s marked as paid" % payment.id)
return redirect(url_for('admin_txns'))
return render_template('admin/txn-reconcile.html', txn=txn, payment=payment, form=form)
示例5: notification_del_detail
def notification_del_detail(g_id, item, value):
db = connect_db()
group = db.notifications.find_one({"id": g_id})
if not group:
return "unknown group " + g_id
# TODO handle restricted groups
# if group.restricted:
# return 'restricted group'
if item == "emails":
print value
print group["active_emails"]
if value not in group["active_emails"]:
return "Cannot complete this action"
i = {
"address": value,
"type": "unsubscription",
"token": sha1("".join([chr(randint(32, 122)) for x in range(12)])).hexdigest(),
"date": datetime.now(),
}
group["actions"].append(i)
msg = Message(
"Parltrack Notification Unsubscription Verification",
sender="[email protected]",
recipients=[value],
)
msg.body = "Your verification key is %sactivate?key=%s\nNotification group url: %snotification/%s" % (
request.url_root,
i["token"],
request.url_root,
g_id,
)
mail.send(msg)
db.notifications.save(group)
return "OK"
示例6: signup
def signup():
if current_user.is_authenticated():
return redirect(url_for('tickets'))
form = SignupForm(request.form, next=request.args.get('next'))
if request.method == 'POST' and form.validate():
user = User(form.email.data, form.name.data)
user.set_password(form.password.data)
db.session.add(user)
try:
db.session.commit()
except IntegrityError, e:
app.logger.warn('Adding user raised %r, assuming duplicate email', e)
flash("This email address %s is already in use. Please log in, or reset your password if you've forgotten it." % (form.email.data))
return redirect(url_for('login'))
login_user(user)
# send a welcome email.
msg = Message("Welcome to Electromagnetic Field",
sender=app.config['TICKETS_EMAIL'],
recipients=[user.email])
msg.body = render_template("welcome-email.txt", user=user)
mail.send(msg)
return redirect(form.next.data or url_for('tickets'))
示例7: notify
def notify(snipe, index):
""" Notify this snipe that their course is open"""
course = '%s:%s:%s' % (snipe.subject, snipe.course_number, snipe.section)
if snipe.user.email:
attributes = {
'email': snipe.user.email,
'subject': snipe.subject,
'course_number': snipe.course_number,
'section': snipe.section,
}
# build the url for prepopulated form
url = 'http://sniper.rutgers.io/?%s' % (urllib.urlencode(attributes))
register_url = 'https://sims.rutgers.edu/webreg/editSchedule.htm?login=cas&semesterSelection=92015&indexList=%s' % (index)
email_text = 'A course (%s) that you were watching looks open. Its index number is %s. Click the link below to register for it!\n\n %s \n\n If you don\'t get in, visit this URL: \n\n %s \n\n to continue watching it.\n\n Send any feedback to [email protected]' % (course, index, register_url, url)
# send out the email
message = Message('[Course Sniper](%s) is open' %(course), sender=EMAIL_SENDER)
message.body = email_text
message.add_recipient(snipe.user.email)
message.add_recipient(snipe.user.email)
mail.send(message)
db.session.delete(snipe)
db.session.commit()
app.logger.warning('Notified user: %s about snipe %s' % (snipe.user, snipe))
示例8: mark_complete
def mark_complete():
"""
Checks to see if a group exists in FAS for the given project and marks the
project complete if it does. We do this this way so that we don't have to
send FAS credentials to this app.
"""
fas = fedora.client.AccountSystem(app.config['FAS_SERVER'],
username=app.config['FAS_USERNAME'],
password=app.config['FAS_PASSWORD'],
insecure=app.config['FAS_INSECURE_SSL'])
hosted_request = HostedRequest.query.filter_by(id=request.args.get('id'))
if hosted_request.count() > 0:
project = hosted_request[0]
if project.completed:
return jsonify(error="Request was already marked as completed.")
group_name = project.scm + project.name
try:
group = fas.group_by_name(group_name)
except:
return jsonify(error="No such group: " + group_name)
project.completed = datetime.now()
db.session.commit()
message = Message("Your Fedora Hosted request has been processed")
message.body = """Hi there,
You're receiving this message because the Fedora Hosted project:
%s
has been set up.
To access to your new repository, do the following:
$ %s
If you've requested a Trac instance, you can visit it at:
https://fedorahosted.org/%s
If you've requested any mailing lists, you should have received separate
emails which contain instructions on how to administrate them.
Sincerely,
Fedora Hosted""" % (
project.name,
scm_push_instructions(project),
project.name)
message.sender = \
"Fedora Hosted <[email protected]>"
if 'PROJECT_OWNER_EMAIL_OVERRIDE' in app.config:
message.recipients = [app.config['PROJECT_OWNER_EMAIL_OVERRIDE']]
else:
message.recipients = ["%[email protected]" % project.owner]
if not app.config['TESTING']:
mail.send(message)
return jsonify(success="Request marked as completed.")
else:
return jsonify(error="No hosted request with that ID could be found.")
示例9: confirm
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)
示例10: send_awaiting_confirm_mail
def send_awaiting_confirm_mail(user):
subject = "We're waiting for your confirmation!!"
mail_to_be_sent = Message(subject=subject, recipients=[user['Members_Email']])
confirmation_url = url_for('activate_user', user_id=user['_id'],
_external=True)
mail_to_be_sent.body = "Dear %s, click here to confirm: %s" %
示例11: register
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)
示例12: sendmail
def sendmail():
task = Task.query.order_by(Task.created).first()
msg = Message("Get things done!",
sender=("GTD", "[email protected]"),
recipients=["[email protected]"])
if not task:
return
msg.body = "Hey,\n how about doing '" + task.title + "'?\n"
msg.body += "It has been waiting for " + task.waited_text()
if task.postponed_count > 0:
msg.body += " and you have postponed it "
msg.body += str(task.postponed_count) + " already"
msg.body += ".\n"
msg.body += "Here is some more information:\n"
if len(task.desc.strip()) > 0:
msg.body += "Description: " + task.desc_text() + "\n"
if task.tags != "":
msg.body += "Tags: " + task.tags + "\n"
if task.due_text():
msg.body += "Due: " + task.due_text() + "\n"
if task.duration_text():
msg.body += "Duration: " + task.duration_text() + "\n"
if len(task.text.strip()) > 0:
msg.body += "Text:\n" + task.text + "\n"
msg.body += "\nMark task done: " + conf.SITE_URL + "do/" + str(task.id)+"/\n"
msg.body += "Postpone to later: " + conf.SITE_URL + "postpone/" + str(task.id) + "/"
mail.send(msg)
示例13: new_jam
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)
示例14: notify
def notify(data,d):
if not 'epdoc' in data: return
m=db.notifications.find({'dossiers': data['epdoc']},['active_emails'])
for g in m:
if len(g['active_emails'])==0:
continue
msg = Message("[PT-Com] %s: %s" %
(data['committee'],
data['title']),
sender = "[email protected]",
bcc = g['active_emails'])
msg.body = (u"Parltrack has detected %s%s on the schedule of %s \n"
u"\n on %s"
u"\n%s"
u"%s"
u"\nsee the details here: %s\n"
u"\nYour Parltrack team" %
(u"a change on " if d else u'',
data['epdoc'],
data['committee'],
data['date'] if 'date' in data else 'unknown date',
("\n - %s" % u'\n - '.join(data['list'])) if 'list' in data and len(data['list'])>0 else u"",
"\n %s" % (textdiff(d) if d else ''),
"%s/dossier/%s" % (ROOT_URL, data['epdoc']),
))
mail.send(msg)
示例15: send_notify
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)