本文整理匯總了Python中django.conf.settings.EMAIL_HOST屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.EMAIL_HOST屬性的具體用法?Python settings.EMAIL_HOST怎麽用?Python settings.EMAIL_HOST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.EMAIL_HOST屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_table
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def send_table(sender, recipient, subject, table, send_empty=False):
if send_empty is False and table.has_body() is False:
return
try:
validate_email(sender)
validate_email(recipient)
except Exception:
return
config = Configuration.conf()
host, port = Configuration.get_smtp_server()
settings.EMAIL_HOST = host
settings.EMAIL_PORT = int(port)
settings.EMAIL_USE_TLS = config.get('smtp_ssl')
settings.EMAIL_HOST_USER = config.get('smtp_user')
settings.EMAIL_HOST_PASSWORD = config.get('smtp_password')
send_mail(subject, unicode(table), sender, [recipient], fail_silently=False)
示例2: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def __init__(self, host=None, port=None, username=None, password=None,
use_tls=None, fail_silently=False, use_ssl=None, timeout=None,
ssl_keyfile=None, ssl_certfile=None,
**kwargs):
super(EmailBackend, self).__init__(fail_silently=fail_silently)
self.host = host or settings.EMAIL_HOST
self.port = port or settings.EMAIL_PORT
self.username = settings.EMAIL_HOST_USER if username is None else username
self.password = settings.EMAIL_HOST_PASSWORD if password is None else password
self.use_tls = settings.EMAIL_USE_TLS if use_tls is None else use_tls
self.use_ssl = settings.EMAIL_USE_SSL if use_ssl is None else use_ssl
self.timeout = settings.EMAIL_TIMEOUT if timeout is None else timeout
self.ssl_keyfile = settings.EMAIL_SSL_KEYFILE if ssl_keyfile is None else ssl_keyfile
self.ssl_certfile = settings.EMAIL_SSL_CERTFILE if ssl_certfile is None else ssl_certfile
if self.use_ssl and self.use_tls:
raise ValueError(
"EMAIL_USE_TLS/EMAIL_USE_SSL are mutually exclusive, so only set "
"one of those settings to True.")
self.connection = None
self._lock = threading.RLock()
示例3: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def __init__(self, host=None, port=None, username=None, password=None,
use_tls=None, fail_silently=False, **kwargs):
super(EmailBackend, self).__init__(fail_silently=fail_silently)
self.host = host or settings.EMAIL_HOST
self.port = port or settings.EMAIL_PORT
if username is None:
self.username = settings.EMAIL_HOST_USER
else:
self.username = username
if password is None:
self.password = settings.EMAIL_HOST_PASSWORD
else:
self.password = password
if use_tls is None:
self.use_tls = settings.EMAIL_USE_TLS
else:
self.use_tls = use_tls
self.connection = None
self._lock = threading.RLock()
示例4: connect
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def connect(self):
"""
Connect to SMTP server.
"""
if self._connection:
raise MailHandlerError("SMTP connection already opened")
try:
if settings.EMAIL_USE_SSL:
self._connection = smtplib.SMTP_SSL(settings.EMAIL_HOST, settings.EMAIL_PORT)
else:
self._connection = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
if settings.EMAIL_USE_TLS:
self._connection.starttls()
except smtplib.SMTPException:
raise MailHandlerError("Invalid hostname, port or TLS settings for SMTP")
try:
if settings.EMAIL_HOST_USER and settings.EMAIL_HOST_PASSWORD:
self._connection.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)
except smtplib.SMTPException:
raise MailHandlerError("Invalid username or password for SMTP")
示例5: send_timelapse_detection_done_email
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def send_timelapse_detection_done_email(_print):
if not settings.EMAIL_HOST:
LOGGER.warn("Email settings are missing. Ignored send requests")
return
subject = 'The Detective is done looking at the time-lapse you uploaded.'
from_email = settings.DEFAULT_FROM_EMAIL
ctx = {
'print': _print,
'unsub_url': 'https://app.thespaghettidetective.com/ent/email_unsubscribe/?list=notification&email={}'.format(_print.user.email),
}
emails = [email.email for email in EmailAddress.objects.filter(user=_print.user)]
message = get_template('email/upload_print_processed.html').render(ctx)
msg = EmailMessage(subject, message,
to=emails,
from_email=from_email,
headers={'List-Unsubscribe': '<{}>, <mailto:support@thespaghettidetective.com?subject=Unsubscribe_notification>'.format(ctx['unsub_url'])},
)
msg.content_subtype = 'html'
msg.send()
示例6: setUp
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def setUp(self):
self._ALLOWED_MIMETYPES = get_allowed_mimetypes()
self._STRIP_UNALLOWED_MIMETYPES = (
strip_unallowed_mimetypes()
)
self._TEXT_STORED_MIMETYPES = get_text_stored_mimetypes()
self.mailbox = Mailbox.objects.create(from_email='from@example.com')
self.test_account = os.environ.get('EMAIL_ACCOUNT')
self.test_password = os.environ.get('EMAIL_PASSWORD')
self.test_smtp_server = os.environ.get('EMAIL_SMTP_SERVER')
self.test_from_email = 'nobody@nowhere.com'
self.maximum_wait_seconds = 60 * 5
settings.EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
settings.EMAIL_HOST = self.test_smtp_server
settings.EMAIL_PORT = 587
settings.EMAIL_HOST_USER = self.test_account
settings.EMAIL_HOST_PASSWORD = self.test_password
settings.EMAIL_USE_TLS = True
super(EmailMessageTestCase, self).setUp()
示例7: send_sms_smtp
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def send_sms_smtp(self, config, recipient):
"""
Sends SMS through SMTP gateway
"""
recipient = recipient.replace(' ', '')
settings.EMAIL_HOST = config.get('smtp_host')
settings.EMAIL_USE_TLS = config.get('smtp_ssl')
settings.EMAIL_HOST_USER = config.get('smtp_user')
settings.EMAIL_HOST_PASSWORD = config.get('smtp_password')
send_mail(recipient, self.body, self.sender, [config['sms_smtp_address']])
示例8: send_email_smtp
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def send_email_smtp(self, email: EmailMultiAlternatives) -> None:
from_email = email.from_email
to = get_forward_address()
msg = EmailMessage()
msg['Subject'] = email.subject
msg['From'] = from_email
msg['To'] = to
text = email.body
html = email.alternatives[0][0]
# Here, we replace the email addresses used in development
# with chat.zulip.org, so that web email providers like Gmail
# will be able to fetch the illustrations used in the emails.
localhost_email_images_base_uri = settings.ROOT_DOMAIN_URI + '/static/images/emails'
czo_email_images_base_uri = 'https://chat.zulip.org/static/images/emails'
html = html.replace(localhost_email_images_base_uri, czo_email_images_base_uri)
msg.add_alternative(text, subtype="plain")
msg.add_alternative(html, subtype="html")
smtp = smtplib.SMTP(settings.EMAIL_HOST)
smtp.starttls()
smtp.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)
smtp.send_message(msg)
smtp.quit()
示例9: test_mail_not_set_up
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def test_mail_not_set_up(self):
with setenv('ALLOW_SIGNUP', 'True'):
if hasattr(settings, 'EMAIL_HOST'):
has_EMAIL_HOST = True
EMAIL_HOST = settings.EMAIL_HOST
delattr(settings, 'EMAIL_HOST')
else:
has_EMAIL_HOST = False
if hasattr(settings, 'EMAIL_BACKEND'):
has_EMAIL_BACKEND = True
EMAIL_BACKEND = settings.EMAIL_BACKEND
delattr(settings, 'EMAIL_BACKEND')
else:
has_EMAIL_BACKEND = False
request = HttpRequest()
request.method = 'POST'
response = SignupView.as_view()(request, as_string=True)
if has_EMAIL_HOST:
settings.EMAIL_HOST = EMAIL_HOST
if has_EMAIL_BACKEND:
settings.EMAIL_BACKEND = EMAIL_BACKEND
needle = "<span>has not set up any emails</span>"
self.assertInHTML(needle, str(response.content))
示例10: send_failure_alert_email
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def send_failure_alert_email(printer, rotated_jpg_url, is_warning, print_paused):
if not settings.EMAIL_HOST:
LOGGER.warn("Email settings are missing. Ignored send requests")
return
subject = 'Your print {} on {} {}.'.format(
printer.current_print.filename or '',
printer.name,
'smells fishy' if is_warning else 'is probably failing')
ctx = {
'printer': printer,
'print_paused': print_paused,
'is_warning': is_warning,
'view_link': site.build_full_url('/printers/'),
'cancel_link': site.build_full_url('/prints/{}/cancel/'.format(printer.current_print_id)),
'resume_link': site.build_full_url('/prints/{}/resume/'.format(printer.current_print_id)),
}
send_email(
user=printer.user,
subject=subject,
mailing_list='alert',
template_path='email/failure_alert.html',
ctx=ctx,
img_url=rotated_jpg_url,
)
示例11: send_email
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def send_email(user, subject, mailing_list, template_path, ctx, img_url=None, verified_only=True, attachment=None):
if not settings.EMAIL_HOST:
LOGGER.warn("Email settings are missing. Ignored send requests")
return
attachments = []
if img_url:
# https://github.com/TheSpaghettiDetective/TheSpaghettiDetective/issues/43
try:
if not ipaddress.ip_address(urlparse(img_url).hostname).is_global:
attachments = [('Image.jpg', requests.get(img_url).content, 'image/jpeg')]
except:
pass
ctx['img_url'] = None if attachments else img_url
# By default email verification should be required for notifications but
# maybe users will want to disable it on private servers
if settings.ACCOUNT_EMAIL_VERIFICATION != 'none' and verified_only:
emails = EmailAddress.objects.filter(user=user, verified=True)
else:
emails = EmailAddress.objects.filter(user=user)
unsub_url = site.build_full_url(f'/unsubscribe_email/?unsub_token={user.unsub_token}&list={mailing_list}')
for email in emails:
ctx['unsub_url'] = unsub_url
message = get_template(template_path).render(ctx)
msg = EmailMessage(
subject,
message,
to=(email.email,),
from_email=settings.DEFAULT_FROM_EMAIL,
attachments=attachments,
headers={'List-Unsubscribe': f'<{unsub_url}>, <mailto:support@thespaghettidetective.com?subject=Unsubscribe_{mailing_list}>'},)
msg.content_subtype = 'html'
if attachment:
msg.attach_file(attachment)
msg.send()
示例12: _send
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import EMAIL_HOST [as 別名]
def _send(subject, message, recipient_list,
email_config=None, html_message=None, fail_silently=False):
if not email_config:
blog_config = get_config_by_name(v2_app_config_context['v2_blog_config']).v2_real_config
email_config = blog_config['email']
username = email_config.get('username', None) or settings.EMAIL_HOST_USER
password = email_config.get('password', None)
if password:
password = descrypt(unsign(password))
else:
password = settings.EMAIL_HOST_PASSWORD
smtp = email_config.get('smtp', None) or settings.EMAIL_HOST
port = email_config.get('port', None) or settings.EMAIL_PORT
secure = email_config.get('secure', None)
if not secure:
if settings.EMAIL_USE_TLS:
secure = 'tls'
elif settings.EMAIL_USE_SSL:
secure = 'ssl'
if not username or not password or not smtp or not port:
return
kwargs = {
'host': smtp,
'port': port,
'username': username,
'password': password,
'fail_silently': fail_silently
}
if secure == 'tls':
kwargs['use_tls'] = True
elif secure == 'ssl':
kwargs['use_ssl'] = True
connection = EmailBackend(**kwargs)
mail = EmailMultiAlternatives(subject, message, username, recipient_list, connection=connection)
if html_message:
mail.attach_alternative(html_message, 'text/html')
a= mail.send()
print(a)