コード例 #1
0
ファイル: inform.py プロジェクト: Evanavevan/Send-Email
    def post(self):
        data = self.parse_json_body()
        try:
            company = data["company"]
            verify_link = data["verify_link"]
            receivers = data["receivers"]
        except KeyError:
            self.write_error(400, desc="parameter wrong")
            return

        template = email_dict["operator_inform_email"]["template"]
        subject = email_dict["operator_inform_email"]["subject"]
        sender = settings["email"]["mail_user"]
        try:
            template_email_core.login(sender, settings["email"]["mail_pwd"])
            for receiver in receivers:
                msg = template_email_core.generate_msg(
                    template_file=template,
                    sender=sender,
                    receiver=receiver,
                    subject=subject,
                    client=receiver.split("@")[0],
                    company=company,
                    verify_link=verify_link)
            template_email_core.send_email(sender=sender,
                                           receivers=receiver,
                                           msg=msg)
        except Exception as e:
            logging.exception("send email exception: {}".format(e))
            self.write_error(500, desc="send email failed")
            return
        self.write_success_json()
コード例 #2
0
ファイル: inform.py プロジェクト: Evanavevan/Send-Email
    def post(self):
        data = self.parse_json_body()
        try:
            is_success = data["is_success"]
            receivers = data["receivers"]
            application_name = data["application_name"]
            application_version = data["application_version"]
            verify_link = data["verify_link"]
            if is_success:
                reason = None
                template = email_dict["application_verify_success_email"][
                    "template"]
                subject = email_dict["application_verify_success_email"][
                    "subject"]
            else:
                reason = data["reason"]
                template = email_dict["application_verify_fail_email"][
                    "template"]
                subject = email_dict["application_verify_fail_email"][
                    "subject"]
        except KeyError:
            self.write_error(400, desc="parameter wrong")
            return

        sender = settings["email"]["mail_user"]
        try:
            template_email_core.login(sender, settings["email"]["mail_pwd"])
            for receiver in receivers:
                msg = template_email_core.generate_msg(
                    template_file=template,
                    sender=sender,
                    receiver=receiver,
                    subject=subject,
                    client=receiver.split("@")[0],
                    verify_link=verify_link,
                    reason=reason,
                    application_name=application_name,
                    application_version=application_version)
            template_email_core.send_email(sender=sender,
                                           receivers=receiver,
                                           msg=msg)
        except Exception as e:
            logging.exception("send email exception: {}".format(e))
            self.write_error(500, desc="send email failed")
            return
        self.write_success_json()
コード例 #3
0
ファイル: queue_inform.py プロジェクト: Evanavevan/Send-Email
def OperatorInformHandler(info):
    """
    操作员通知邮件发送
    info: dict {"company": x, "email_addresses": x}
    """
    email_addresses = info.get("email_addresses")
    company = info.get("company")
    verify_link = info.get("verify_link")

    template = controllers.parse_message.email_dict["operator_inform_email"]["template"]
    subject = controllers.parse_message.email_dict["operator_inform_email"]["subject"]

    if not email_addresses or not company:
        logging.error("email_addresses and company not complete")
        return False

    try:
        template_email_core.login(
            settings["email"]["mail_user"],
            settings["email"]["mail_pwd"])

        sender = settings["email"]["mail_user"]
        for email_address in email_addresses:
            msg = template_email_core.generate_msg(
                template_file=template,
                sender=sender,
                receiver=email_address,
                subject=subject,
                company=company,
                verify_link=verify_link,
                client=email_address.split("@")[0])

            template_email_core.send_email(
                sender=sender,
                receivers=email_address,
                msg=msg)
    except Exception as e:
        logging.exception("send email exception: {}".format(e))
        return False
    return True