当前位置: 首页>>代码示例>>Python>>正文


Python message.EmailMessage方法代码示例

本文整理汇总了Python中django.core.mail.message.EmailMessage方法的典型用法代码示例。如果您正苦于以下问题:Python message.EmailMessage方法的具体用法?Python message.EmailMessage怎么用?Python message.EmailMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.mail.message的用法示例。


在下文中一共展示了message.EmailMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: expiring_warning_email

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def expiring_warning_email(recipients, roles, url, cc=[]):
        """
        Send one expiry warning email
        """
        from django.core.mail.message import EmailMessage
        expiring_list = '\n'.join(
            '  - %s as a %s in %s on %s.' % (r.person.name(), r.get_role_display(), r.unit.name, r.expiry)
            for r in roles
        )
        message = 'The following administrative roles within %s are expiring soon:\n\n%s\n\n' \
                  'If these roles are still appropriate, please renew them soon by visiting this page: %s\n\n' \
                  'This might be a good time to see if any other roles need to be revoked as well.\n' \
                  'Thanks, your friendly automated reminder.' % (product_name(hint='admin'), expiring_list, url)

        mail = EmailMessage(
            subject=product_name(hint='admin') + ' roles expiring',
            body=message,
            from_email=help_email(hint='admin'),
            to=recipients,
            cc=cc,
        )
        mail.send() 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:models.py

示例2: transform_sms_to_email_message

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def transform_sms_to_email_message(sms_message):
	backend = getattr(settings, "SMSISH_MAILTRAP_SMS_BACKEND_EMAIL_BACKEND", DEFAULT_SMS_OVER_EMAIL_BACKEND)
	conn = get_connection(backend=backend)
	email = EmailMessage(
		subject="SMS over Email",
		body=sms_message.body,
		from_email=emailify_phone_number(sms_message.from_email),
		to=[emailify_phone_number(r) for r in sms_message.to],
		bcc=[emailify_phone_number(r) for r in sms_message.bcc] if sms_message.bcc else None,
		connection=conn,
		attachments=None,
		headers=None,
		cc=[emailify_phone_number(r) for r in sms_message.cc] if sms_message.cc else None,
		reply_to=[emailify_phone_number(sms_message.reply_to) for r in sms_message.reply_to] if sms_message.reply_to else None,
	)
	email.attach("metadata.txt", "Content-Length: {}".format(len(sms_message.body)), "text/plain")

	return email 
开发者ID:RyanBalfanz,项目名称:django-smsish,代码行数:20,代码来源:mailtrap.py

示例3: send_mme_contact_email

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def send_mme_contact_email(request, matchmaker_result_guid):
    """
    Sends the given email and updates the contacted status for the match
    Args:
        matchmaker_result_guid
    Returns:
        Status code and results
    """
    result = MatchmakerResult.objects.get(guid=matchmaker_result_guid)
    check_mme_permissions(result.submission, request.user)

    request_json = json.loads(request.body)
    email_message = EmailMessage(
        subject=request_json['subject'],
        body=request_json['body'],
        to=[s.strip() for s in request_json['to'].split(',')],
        from_email=MME_DEFAULT_CONTACT_EMAIL,
    )
    try:
        email_message.send()
    except Exception as e:
        message = str(e)
        json_body = {}
        if hasattr(e, 'response'):
            message = e.response.content
            try:
                json_body = e.response.json()
            except Exception:
                json_body = {'message':message}
        return create_json_response(json_body, status=getattr(e, 'status_code', 400), reason=message)

    update_model_from_json(result, {'weContacted': True})

    return create_json_response({
        'mmeResultsByGuid': {matchmaker_result_guid: {'matchStatus': _get_json_for_model(result)}},
    }) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:38,代码来源:matchmaker_api.py

示例4: view

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def view(self, post=False):
        leagues = [self.league] + list(
            League.objects.filter(is_active=True).order_by('display_order').exclude(
                pk=self.league.pk))
        if post:
            form = ContactForm(self.request.POST, leagues=leagues)
            if form.is_valid():
                league = League.objects.get(tag=form.cleaned_data['league'])
                for mod in league.leaguemoderator_set.all():
                    if mod.send_contact_emails and mod.player.email:
                        message = EmailMessage(
                            '[%s] %s' % (league.name, form.cleaned_data['subject']),
                            'Sender:\n%s\n%s\n\nMessage:\n%s' %
                            (form.cleaned_data['your_lichess_username'],
                             form.cleaned_data['your_email_address'], form.cleaned_data['message']),
                            settings.DEFAULT_FROM_EMAIL,
                            [mod.player.email]
                        )
                        message.send()
                return redirect(leagueurl('contact_success', league_tag=self.league.tag))
        else:
            form = ContactForm(leagues=leagues)

        context = {
            'form': form,
        }
        return self.render('tournament/contact.html', context) 
开发者ID:cyanfish,项目名称:heltour,代码行数:29,代码来源:views.py

示例5: send_messages

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def send_messages(self, email_messages):
    if not email_messages:
      return

    for message in email_messages:

      content = {}
      if isinstance(message, EmailMessage):
        content["text/%s" % message.content_subtype] = message.body

      if isinstance(message, EmailMultiAlternatives):
        for alt in message.alternatives:
          content[alt[1]] = alt[0]

      output = '''
----------------------------------------
Redirecting email to log.

From: %s
To: %s
Bcc: %s
Subject: %s
''' % (
        repr(message.from_email),
        repr(message.to),
        repr(message.bcc),
        repr(message.subject),
      )
      for n, v in message.extra_headers.items():
        output += '%s: %s\n' % (n, repr(v))
      for contentType, content in content.items():
        output += '\n'
        output += '-- Email body as %s --\n' % contentType
        output += content
        output += '\n'
        output += '-- End of email body as %s --\n' % contentType
      output += '-' * 40
      output += '\n'
      logger.info(output) 
开发者ID:Polychart,项目名称:builder,代码行数:41,代码来源:emailConsole.py

示例6: _generate_notification_for_seqr_match

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def _generate_notification_for_seqr_match(submission, results):
    """
    Generate a notifcation to say that a match happened initiated from a seqr user.
    """
    matches = []
    hpo_terms_by_id, genes_by_id, _ = get_mme_genes_phenotypes_for_results(results)
    for result in results:
        patient = result['patient']

        gene_message = ''
        if patient.get('genomicFeatures'):
            gene_symbols = set()
            for gene in patient['genomicFeatures']:
                gene_symbol = gene['gene']['id']
                if gene_symbol.startswith('ENSG'):
                    gene_symbol = genes_by_id.get(gene_symbol, {}).get('geneSymbol', gene_symbol)
                gene_symbols.add(gene_symbol)

            gene_message = ' with genes {}'.format(' '.join(sorted(gene_symbols)))

        phenotypes_message = ''
        if patient.get('features'):
            phenotypes_message = ' with phenotypes {}'.format(' '.join(
                ['{} ({})'.format(feature['id'], hpo_terms_by_id.get(feature['id'])) for feature in patient['features']]
            ))

        matches.append(' - From {contact} at institution {institution}{gene_message}{phenotypes_message}.'.format(
            contact=patient['contact'].get('name', '(none given)'),
            institution=patient['contact'].get('institution', '(none given)'),
            gene_message=gene_message, phenotypes_message=phenotypes_message,
        ))

    individual = submission.individual
    project = individual.family.project
    message = """
    A search from a seqr user from project {project} individual {individual_id} had the following new match(es):
    
    {matches}
    
    {host}project/{project_guid}/family_page/{family_guid}/matchmaker_exchange
    """.format(
        project=project.name, individual_id=individual.individual_id, matches='\n\n'.join(matches),
        host=BASE_URL, project_guid=project.guid, family_guid=submission.individual.family.guid,
    )

    post_to_slack(MME_SLACK_SEQR_MATCH_NOTIFICATION_CHANNEL, message)
    emails = [s.strip().split('mailto:')[-1] for s in submission.contact_href.split(',')]
    email_message = EmailMessage(
        subject='New matches found for MME submission {} (project: {})'.format(individual.individual_id, project.name),
        body=message,
        to=[email for email in emails if email != MME_DEFAULT_CONTACT_EMAIL],
        from_email=MME_DEFAULT_CONTACT_EMAIL,
    )
    email_message.send() 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:56,代码来源:matchmaker_api.py

示例7: send_messages

# 需要导入模块: from django.core.mail import message [as 别名]
# 或者: from django.core.mail.message import EmailMessage [as 别名]
def send_messages(self, email_messages):

    if not email_messages:
      return
    errors = []

    for message in email_messages:

      content = {}
      if isinstance(message, EmailMessage):
        content["text/%s" % message.content_subtype] = message.body

      if isinstance(message, EmailMultiAlternatives):
        for alt in message.alternatives:
          content[alt[1]] = alt[0]

      message_dict = {
        'api_key': getattr(settings, "EMAIL_POSTAGEAPP_API_KEY"),
        'arguments': {
          'recipients': message.to,
          'headers': {
            "subject": message.subject,
            "from": message.from_email,
            "bcc": message.bcc,
          },
          'content': content,
        }
      }

      if getattr(message, "extra_headers"):
        message_dict["arguments"]["headers"].update(message.extra_headers)

      try:
        req = urllib2.Request(self.postageapp_endpoint, json.dumps(message_dict), {'Content-Type': 'application/json'})
        response = urllib2.urlopen(req)

      except urllib2.HTTPError, e:
        jsonobj = None
        try: jsonobj = json.loads(e.read())
        except Exception, e: pass

        if jsonobj is not None: errors.append(jsonobj)
        else: errors.append('Unknown Error') 
开发者ID:Polychart,项目名称:builder,代码行数:45,代码来源:postageapp.py


注:本文中的django.core.mail.message.EmailMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。