本文整理匯總了Python中models.Email.send_at方法的典型用法代碼示例。如果您正苦於以下問題:Python Email.send_at方法的具體用法?Python Email.send_at怎麽用?Python Email.send_at使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Email
的用法示例。
在下文中一共展示了Email.send_at方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_email
# 需要導入模塊: from models import Email [as 別名]
# 或者: from models.Email import send_at [as 別名]
def send_email(data):
"""
This is a helper function for sending emails based on the settings
provided in the settings.py file.
"""
if not settings.URL:
abort(500,'Email provider URL is not set')
if not settings.API_KEY:
abort(500,'Email provider API_KEY is not set')
status = False
if settings.EMAIL_PROVIDER == 'MAILGUN':
status = send_email_using_mailgun(data, settings.URL, settings.API_KEY)
if status != 'success' and settings.AUTO_SWITCH_EMAIL_PROVIDER: #check to auto switch email provider
return send_email_using_mandrill(data, settings.ALT_URL, settings.ALT_API_KEY)
elif settings.EMAIL_PROVIDER == 'MANDRILL':
status = send_email_using_mandrill(data, settings.URL, settings.API_KEY)
if status != 'success' and settings.AUTO_SWITCH_EMAIL_PROVIDER: #check to auto switch email provider
return send_email_using_mailgun(data, settings.ALT_URL, settings.ALT_API_KEY)
if status == 'success': #Storing emails sent in the database
email = Email(to_name=data['to_name'], to_email=data['to'],
from_email=data['from'], from_name=data['from_name'],
subject=data['subject'], body=data['body'])
if 'send_at' in data and data['send_at']:
email.send_at = data['send_at']
db_session.add(email)
db_session.commit()
return status