本文整理汇总了Python中flask.ext.mail.Mail类的典型用法代码示例。如果您正苦于以下问题:Python Mail类的具体用法?Python Mail怎么用?Python Mail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adoptPuppyPage
def adoptPuppyPage(puppy_id):
""" Provides a page where adopters can adopt a puppy. """
puppy = session.query(Puppy).filter_by(id=puppy_id).one()
if request.method == 'POST':
try:
# Change the adopter_puppy field of adopter to reflect the puppy.
adopter_id = int(request.form['adopterIDField'])
adopter = session.query(Adopter).filter_by(id=adopter_id).one()
adopter.adopted_puppy = puppy.id
session.add(adopter)
# Change the shelter id of the puppy to None since it has a home.
puppy.shelter_id = None
session.add(puppy)
session.commit()
# Create a mail instance for use with sending messages.
mail = Mail(app)
msg = Message("Hello Em, thanks for adopting %s" % puppy.name,
sender="[email protected]",
recipients=["[email protected]"])
mail.send(msg)
return redirect(url_for('puppyList'))
except:
print "The adoption process was unsuccessful."
return redirect(url_for('puppyList'))
else:
return render_template('adopt_puppy.html', puppy=puppy)
示例2: register
def register():
owner = "[email protected]"
sysadmin = "[email protected]"
name = request.form.get('name', None)
email = request.form.get('email', None)
institute = request.form.get('institute', None)
message = request.form.get('message', None)
app =Flask(__name__)
mail=Mail(app)
_subject = "[Multinet] Request Access Form: %s, %s" % ( name, email )
#1.check if user exists, generate access url for user and save user to db
_token = generate_id()
udata = { "email" : email,"name" : name,"institute" : institute,"message" : message, "token": _token }
ret = insert_user(udata)
if not ret:
return render_template('start.html',errors="This email address is already registered.")
#2.send new user to admin
try:
msg = Message( subject=_subject , recipients=[ owner ], body=message, sender=sysadmin )
mail.send(msg)
except Exception,e:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_tb(exc_traceback, limit=5, file=sys.stdout)
示例3: send_email
def send_email(msg):
from routes import app
with app.app_context():
mail = Mail()
mail.init_app(current_app)
print("hallo world")
mail.send(msg)
示例4: send_pdf_by_email
def send_pdf_by_email(invoice_id):
form = InvoiceEmail(request.form)
if not form.validate():
return form.errors_as_json()
invoice = Invoice.find_by_id(invoice_id)
if not invoice:
return abort(404)
message = Message(form.subject.data.encode('utf-8'), sender=(g.member.display, g.member.get_email().encode('utf-8')))
message.add_recipient(sanitize_address((form.name.data, form.email.data)))
message.body = form.message.data.encode('utf-8')
invoice_key = amazons3.get_invoice(invoice)
message.attach("Invoice_{0}.pdf".format(invoice.reference), "application/pdf", invoice_key.get_contents_as_string())
mail = Mail()
mail.init_app(current_app)
mail.send(message)
history = InvoiceHistory()
history.description = 'Sent email to {0}'.format(message.recipients[0])
history.pdf = invoice_key.key
history.status = 'SENT'
history.misc = "{0}\n\n{1}".format(message.subject, message.body)
history.member_id = g.member.id
history.invoice_id = invoice.id
history.save()
return 'sent', 200
示例5: send_message
def send_message(subject, body, html=False, caps_gs_sem=False):
from sync import app
mail = Mail(app)
if caps_gs_sem:
recipients = CAPS_GS_SEM_RECIPIENTS
else:
recipients = ADMIN_RECIPIENTS
msg = Message(subject=subject,
sender="[email protected]",
recipients=recipients)
if html:
msg.html = body
else:
msg.body = body
try:
mail.send(msg)
except socket.error:
print "failed to send message %s" % body
return False
return True
示例6: UserMail
def UserMail(user, passwd, smtp, smtp_port, smtp_tsl, smtp_auth, data):
mail_user = user
mail_passwd = passwd
print "--- DEBUG ---"
print "--- DEBUG ---"
print data
print "--- DEBUG ---"
print "--- DEBUG ---"
from_addr = user
to_addr = ';'.join(data.get("from_mail"))
print to_addr
mail = Mail(current_app)
current_app.config.update(
MAIL_SERVER=smtp,
MAIL_PORT=smtp_port,
MAIL_USE_SSL=smtp_auth,
MAIL_USE_TLS=smtp_tsl,
MAIL_USERNAME=mail_user,
MAIL_PASSWORD=mail_passwd
)
mail.init_app(current_app)
msg = Message('Reztoran', sender=from_addr, recipients=to_addr.split(";"))
msg.html = data.get("text")
msg.subject = data.get('title')
mail.send(msg)
return "ok"
示例7: test_send_email
def test_send_email():
mailForm= MailForm()
if mailForm.validate_on_submit():#表单提交成功的判断
try:
app = Flask(__name__)
app.config['SECRET_KEY'] = 'qiyeboy'
#下面是SMTP服务器配置
app.config['MAIL_SERVER'] = 'smtp.163.com' #电子邮件服务器的主机名或IP地址
app.config['MAIL_PORT'] = '25' #电子邮件服务器的端口
app.config['MAIL_USE_TLS'] = True #启用传输层安全
app.config['MAIL_USERNAME'] ='[email protected]' #os.environ.get('MAIL_USERNAME') #邮件账户用户名
app.config['MAIL_PASSWORD'] = 'hywd1993'#os.environ.get('MAIL_PASSWORD') #邮件账户的密码
mail = Mail(app)
receiverName = mailForm.receiver.data #收件人文本框的内容
styledata = mailForm.style.data#主题文本框的内容
bodydata = mailForm.body.data#正文文本框的内容
msg = Message(styledata,sender='[email protected]',recipients=[receiverName])#发件人,收件人
msg.body = bodydata
# send_email('[email protected]','Test email-function',)
mail.send(msg)
flash('邮件发送成功!')#提示信息
return redirect(url_for('.index'))
except:
flash('邮件发送失败!')
return redirect(url_for('.index'))
return render_template('testemail.html',form=mailForm,name ='[email protected]' )#渲染网页
# @main.route('/secret')
# @login_required
# def secret():
# return 'Only authenticated users are allowed!'
示例8: send_email
def send_email(to, subject, template, **kwargs):
mail = Mail(app)
msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
sender=app.config['FLASKY_MAIL_SENDER'], recipients=[to])
msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs)
mail.send(msg)
示例9: add_post_post
def add_post_post():
members = session.query(User).all()
post = Post(
title=request.form["title"],
content=mistune.markdown(request.form["content"]),
description = request.form["description"],
author=current_user
)
session.add(post)
session.commit()
all_members = []
for member in members:
all_members.append(member.email)
all_members = [str(i) for i in all_members]
describe = request.form["description"] +".... View full message on TeamForum!"
mail=Mail(app)
with mail.connect() as conn:
for email in all_members:
message = Message(subject="A new forum has been created by "+ current_user.name,
body= describe,
sender=("TeamForum", "[email protected]"),
recipients=[email]
)
conn.send(message)
flash("You have created a new forum. Team members have been notified.", "info")
return redirect(url_for("posts"))
示例10: send_email
def send_email(to,subject,template):
mail = Mail(application)
mail.init_app(application)
msg = Message(
subject,recipients = [to],
html = template,
sender = application.config['MAIL_USERNAME'])
mail.send(msg)
示例11: sendConfirmation
def sendConfirmation(app, teamEmail, html = None):
if not configSet :
setConfigOptions(app)
mail = Mail(app)
msg = Message(subject=_subject, sender=_mailDefaultSender, recipients=[teamEmail], bcc=[_mailDefaultSender])
msg.body = getEmailTemplate()
msg.html = html
mail.send(msg)
示例12: send_email
def send_email(email, pdf):
mail_ext = Mail(app)
subject = "Phone Notes"
receiver = "[email protected]"
mail_to_be_sent = Message(subject=subject, recipients=[receiver])
mail_to_be_sent.body = "This email contains PDF."
mail_to_be_sent.attach("file.pdf", "application/pdf", pdf)
mail_ext.send(mail_to_be_sent)
示例13: send_email
def send_email(subject, text):
""" Send email """
msg = Message(subject, sender='[email protected]',
recipients=['[email protected]'])
msg.body = text
mail = Mail(current_app)
mail.send(msg)
示例14: send
def send(MessageClass, **kwargs):
with app.test_request_context():
mailer = Mail(app)
mailer.send(MessageClass(**kwargs))
if 'to' in kwargs:
return "Mail type: %s, recipient: %s" % (MessageClass.desc(), kwargs['to'])
return True
示例15: count_words_at_url
def count_words_at_url(url, mailAddress):
resp = requests.get(url)
result = len(resp.text.split())
mail = Mail(current_app)
msg = Message("test", recipients=["[email protected]"])
msg.body = str(result)
msg.add_recipient(str(mailAddress))
mail.send(msg)
return result