def post(self):
        try:
            message_schema = MessageSchema()
            new_msg = message_schema.load(request.json)
        except ValidationError as err:
            return {"message": err.messages}, HTTPStatus.BAD_REQUEST
        msg = Message(subject='Email z cfp_v3 od {}'.format(new_msg["name"]),
                      sender=new_msg["email"],
                      reply_to=new_msg["email"],
                      recipients=["*****@*****.**"])
        msg.body = 'Nowa wiadomość od {}, nr tel: {} \nTreść:\n {}'.format(
            new_msg["name"], new_msg["phone"], new_msg["content"])
        mail.send(msg)

        return {"message": "Contact message successfully sent"}, HTTPStatus.OK
Beispiel #2
0
    def post(self):
        try:
            message_schema = MessageSchema()
            new_msg = message_schema.load(request.json)
        except ValidationError as err:
            return {"message": err.messages}, HTTPStatus.BAD_REQUEST
        name, phone, content = new_msg["name"], new_msg["phone"], new_msg[
            "content"]
        base_url = os.environ.get("BASE_URL", "codeforpoznan.pl")

        msg = Message(
            subject=f"Email z {base_url} od {name}",
            sender=new_msg["email"],
            reply_to=new_msg["email"],
            recipients=[f"hello@{base_url}"],
        )
        msg.body = f"Nowa wiadomość od {name}, nr tel: {phone} \nTreść:\n {content}"
        mail.send(msg)

        return {"message": "Contact message successfully sent"}, HTTPStatus.OK
Beispiel #3
0
    def post(self):
        try:
            message_schema = MessageSchema()
            data = message_schema.load(request.json)
        except ValidationError as err:
            return {"message": err.messages}, HTTPStatus.BAD_REQUEST

        sender_email = data["email"]
        context = {"base_url": self.base_url, **data}

        try:
            # mail from someone (via form) to us, send internal message
            self.send_message(
                context=context,
                subject=self.internal_message_subject,
                body=self.internal_message_body,
                sender=self.notify_addr,
                reply_to=self.notify_addr,
                recipients=[self.hello_addr],
            )

            # mail from us to someone, send pretty external message
            self.send_message(
                context=context,
                subject=self.external_message_subject,
                body=self.external_message_body,
                sender=self.notify_addr,
                reply_to=self.hello_addr,
                recipients=[sender_email],
            )

        except MessageError:
            return (
                {
                    "message": "Failed to send contact message"
                },
                HTTPStatus.SERVICE_UNAVAILABLE,
            )

        return {"message": "Contact message successfully sent"}, HTTPStatus.OK