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


Python mail.send_mail方法代码示例

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


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

示例1: send

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send(self):
        result = None
        self.recipient = self.recipient.strip()

        try:
            validate_phone_number(self.recipient)
            result = self.send_sms()
        except ValidationError:
            pass

        try:
            validate_email(self.recipient)
            result = self.send_mail()
        except ValidationError:
            pass

        self.save()
        return result 
开发者ID:fpsw,项目名称:Servo,代码行数:20,代码来源:note.py

示例2: post

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def post(self, request, *args, **kwargs):
        autonomous_system = get_object_or_404(AutonomousSystem, asn=kwargs["asn"])

        if not autonomous_system.can_receive_email:
            redirect(autonomous_system.get_absolute_url())

        form = AutonomousSystemEmailForm(request.POST)
        form.fields[
            "recipient"
        ].choices = autonomous_system.get_contact_email_addresses()

        if form.is_valid():
            sent = send_mail(
                form.cleaned_data["subject"],
                form.cleaned_data["body"],
                settings.SERVER_EMAIL,
                [form.cleaned_data["recipient"]],
            )
            if sent == 1:
                messages.success(request, "Email sent.")
            else:
                messages.error(request, "Unable to send the email.")

        return redirect(autonomous_system.get_absolute_url()) 
开发者ID:respawner,项目名称:peering-manager,代码行数:26,代码来源:views.py

示例3: send_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_mail(self,
                  subject_template_name, email_template_name, context, *args,
                  html_email_template_name=None, **kwargs):
        user_is_active = context['user'].is_active
        html_email_template_name = html_email_template_name[user_is_active]
        email_template_name = email_template_name[user_is_active]
        if not user_is_active:
            case_id = str(uuid4()).upper()
            auth_log.warning(
                (self.admin_inactive_user_notification + ", but the account is deactivated [{cid}].")
                .format(u=context['user'], cid=case_id)
            )
            context['restore_request_id'] = case_id

        args = [subject_template_name, email_template_name, context, *args]
        kwargs.update(html_email_template_name=html_email_template_name)
        context.update({'ENV': settings.ENVIRONMENT, 'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL})
        super().send_mail(*args, **kwargs) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:20,代码来源:forms.py

示例4: send_downgrade_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_downgrade_email(customer):
    from django.core.mail import send_mail
    from django.template.loader import render_to_string

    email_content = render_to_string(
        "billing/email_downgrade.txt",
        context={"username":customer.user.username}
    )

    result = send_mail(
        'Acacia Account Downgraded',
        email_content,
        'noreply@tradeacacia.com',
        [customer.user.email],
        fail_silently=True
    )
    return result == 1 
开发者ID:AcaciaTrading,项目名称:acacia_main,代码行数:19,代码来源:collect.py

示例5: send_activation_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_activation_email(self):
        if not self.activated:
            self.activation_key = code_generator()# 'somekey' #gen key
            self.save()
            #path_ = reverse()
            path_ = reverse('activate', kwargs={"code": self.activation_key})
            full_path = "https://muypicky.com" + path_
            subject = 'Activate Account'
            from_email = settings.DEFAULT_FROM_EMAIL
            message = f'Activate your account here: {full_path}'
            recipient_list = [self.user.email]
            html_message = f'<p>Activate your account here: {full_path}</p>'
            print(html_message)
            sent_mail = send_mail(
                            subject, 
                            message, 
                            from_email, 
                            recipient_list, 
                            fail_silently=False, 
                            html_message=html_message)
            sent_mail = False
            return sent_mail 
开发者ID:codingforentrepreneurs,项目名称:Try-Django-1.11,代码行数:24,代码来源:models.py

示例6: email_handler

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def email_handler(args):
    app_model = settings.AUTH_USER_MODEL.split('.')
    user_model = apps.get_model(*app_model)
    recipient = user_model.objects.filter(id__in=args)
    d = {}
    for user in recipient:
        try:
            if not (hasattr(user, 'onlinestatus') and user.onlinestatus.is_online()):
                context = {'receiver': user.username,
                           'unsend_count': user.notifications.filter(unread=True, emailed=False).count(),
                           'notice_list': user.notifications.filter(unread=True, emailed=False),
                           'unread_link': 'http://www.aaron-zhao.com/notifications/unread/'}
                msg_plain = render_to_string("notifications/email/email.txt", context=context)
                result = send_mail("来自[AA的博客] 您有未读的评论通知",
                                   msg_plain,
                                   'support@aaron-zhao.com',
                                   recipient_list=[user.email])
                user.notifications.unsent().update(emailed=True)
                if result == 1:
                    d[user.username] = 1
        except Exception as e:
            print("Error in easy_comment.handlers.py.email_handler: %s" % e)
    return d 
开发者ID:r26zhao,项目名称:django_blog,代码行数:25,代码来源:tasks.py

示例7: send_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_mail(self, project_member_id, project):
        params = {
            "message": self.cleaned_data["message"],
            "project_member_id": project_member_id,
            "project": project,
        }

        plain = render_to_string("email/activity-message.txt", params)
        html = render_to_string("email/activity-message.html", params)

        send_mail(
            "Open Humans: message from project member {}".format(project_member_id),
            plain,
            "no-reply@example.com",
            [project.contact_email],
            html_message=html,
        ) 
开发者ID:OpenHumans,项目名称:open-humans,代码行数:19,代码来源:forms.py

示例8: send_mail_async

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_mail_async(*args, **kwargs):
    """ Using celery to send email async

    You can use it as django send_mail function

    Example:
    send_mail_sync.delay(subject, message, from_mail, recipient_list, fail_silently=False, html_message=None)

    Also you can ignore the from_mail, unlike django send_mail, from_email is not a require args:

    Example:
    send_mail_sync.delay(subject, message, recipient_list, fail_silently=False, html_message=None)
    """
    if len(args) == 3:
        args = list(args)
        args[0] = settings.EMAIL_SUBJECT_PREFIX + args[0]
        args.insert(2, settings.EMAIL_HOST_USER)
        args = tuple(args)

    try:
        send_mail(*args, **kwargs)
    except Exception as e:
        logger.error("Sending mail error: {}".format(e)) 
开发者ID:getway,项目名称:diting,代码行数:25,代码来源:tasks.py

示例9: send_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_email(to, context, template_dir):
    """Render given templates and send email to `to`.

    :param to: User object to send email to..
    :param context: dict containing which needs to be passed to django template
    :param template_dir: We expect files message.txt, subject.txt,
    message.html etc in this folder.
    :returns: None
    :rtype: None

    """

    def to_str(template_name):
        return render_to_string(path.join(template_dir, template_name), context).strip()

    subject = to_str("subject.txt")
    text_message = to_str("message.txt")
    html_message = to_str("message.html")
    from_email = settings.DEFAULT_FROM_EMAIL
    recipient_list = [_format_email(to)]

    return send_mail(
        subject, text_message, from_email, recipient_list, html_message=html_message
    ) 
开发者ID:pythonindia,项目名称:junction,代码行数:26,代码来源:emailer.py

示例10: send_register_active_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_register_active_email(to_email, username, token):
    """发送激活邮件"""
    # 组织邮件内容
    subject = '天天生鲜欢迎信息'
    message = ''
    sender = settings.EMAIL_FROM
    receiver = [to_email]
    html_message = """
                        <h1>%s, 欢迎您成为天天生鲜注册会员</h1>
                        请点击以下链接激活您的账户(7个小时内有效)<br/>
                        <a href="http://127.0.0.1:8000/user/active/%s">http://127.0.0.1:8000/user/active/%s</a>
                    """ % (username, token, token)

    # 发送激活邮件
    # send_mail(subject=邮件标题, message=邮件正文,from_email=发件人, recipient_list=收件人列表)
    send_mail(subject, message, sender, receiver, html_message=html_message) 
开发者ID:ScrappyZhang,项目名称:ecommerce_website_development,代码行数:18,代码来源:tasks.py

示例11: send_register_active_email

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_register_active_email(to_email, username, token):
    """发送激活邮件"""
    # 组织邮件内容
    subject = '天天生鲜欢迎信息'
    message = ''
    sender = settings.EMAIL_FROM
    receiver = [to_email]
    html_message = """
                            <h1>%s, 欢迎您成为天天生鲜注册会员</h1>
                            请点击以下链接激活您的账户<br/>
                            <a href="http://127.0.0.1:8000/user/active/%s">http://127.0.0.1:8000/user/active/%s</a>
                        """ % (username, token, token)

    # 发送激活邮件
    # send_mail(subject=邮件标题, message=邮件正文,from_email=发件人, recipient_list=收件人列表)
    send_mail(subject, message, sender, receiver, html_message=html_message) 
开发者ID:ScrappyZhang,项目名称:ecommerce_website_development,代码行数:18,代码来源:tasks.py

示例12: post

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def post(self, request):
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username','')
            email = form.cleaned_data.get('email', '')
            password = form.cleaned_data.get('password', '')
            users = User()
            users.username = username
            users.password =make_password(password)
            users.email = email
            users.is_active = False
            users.save()
            token = token_confirm.generate_validate_token(username)
            # message = "\n".join([u'{0},欢迎加入我的博客'.format(username), u'请访问该链接,完成用户验证,该链接1个小时内有效',
            #                      '/'.join([settings.DOMAIN, 'activate', token])])
            #send_mail(u'注册用户验证信息', message, settings.EMAIL_HOST_USER, [email], fail_silently=False)
            send_register_email.delay(email=email,username=username,token=token,send_type="register")
            return JsonResponse({'valid':True,'status':200, 'message': u"请登录到注册邮箱中验证用户,有效期为1个小时"})
        return JsonResponse({'status':400,'data':form.errors,'valid':False}) 
开发者ID:fengjinqi,项目名称:website,代码行数:21,代码来源:views.py

示例13: test_send_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def test_send_mail(postmark_request, settings):
    send_mail(**SEND_KWARGS)
    assert postmark_request.call_args[1]["json"] == (
        {
            "ReplyTo": None,
            "Subject": "Subject here",
            "To": "receiver@example.com",
            "Bcc": None,
            "Headers": [],
            "Cc": None,
            "Attachments": [],
            "TextBody": "Here is the message.",
            "HtmlBody": None,
            "Tag": None,
            "Metadata": None,
            "TrackOpens": False,
            "From": "sender@example.com",
        },
    )
    assert postmark_request.call_args[1]["headers"]["X-Postmark-Server-Token"] == settings.POSTMARK["TOKEN"] 
开发者ID:Stranger6667,项目名称:postmarker,代码行数:22,代码来源:test_backend.py

示例14: send_confirmation_mail

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [as 别名]
def send_confirmation_mail(job):
    subject = "You just posted a job on pythonjobs.ie"
    template = loader.get_template("email.html")
    body = template.render({'job': job})
    to_email = [job.email]
    from_email = "info@kimera.io"

    return send_mail(subject, body, from_email, to_email,
                     fail_silently=True, html_message=body) 
开发者ID:kimeraapp,项目名称:pythonjobs.ie,代码行数:11,代码来源:services.py

示例15: send_sms_smtp

# 需要导入模块: from django.core import mail [as 别名]
# 或者: from django.core.mail import send_mail [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']]) 
开发者ID:fpsw,项目名称:Servo,代码行数:13,代码来源:note.py


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