如何使用 Django 的 Parse API 解析来自 Sendgrid 的消息?

发布于 2025-01-07 07:51:12 字数 304 浏览 0 评论 0原文

SendGrid 可以解析传入电子邮件中的附件和内容。应用示例包括通过电子邮件接收上传和发布博客文章。

解析 API 会将解析后的电子邮件 POST 到您帐户中配置的 URL。 SendGrid 自动排队并重试任何响应 5XX 状态错误的 POST。

SendGrid can parse the attachments and contents from incoming emails. Application examples include receiving uploads and posting blog articles via email.

The parse API will POST the parsed email to a URL configured in your account. SendGrid automatically queues and retries any POSTs that respond with a 5XX status error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2025-01-14 07:51:12

对我来说看起来很简单。

class Attachment(Model):
    file = FileField()

class Email(Model):
    headers = TextField()
    text = TextField()
    html = TextField()
    to = TextField()
    cc = TextField()
    subject = TextField()
    dkim = JSONField()
    SPF = JSONField()
    envelope = JSONField()
    charsets = CharField(max_length=255)
    spam_score = FloatField()
    spam_report = TextField()
    attachments = ManyToManyField(Attachment) 

EmailForm(ModelForm)
    attachments = IntegerField()
    class Meta:
        model = Email
        exclude = 'attachments'

@requires_POST
def sendgrid_email_reciever(request):
    form = EmailForm(request.POST)
    if form.is_valid()
        form.instance.save()
        for i in range(1,form.cleaned_data.['attachments']+1):
            attachment = request.FILES['attachment%d' % i]
            form.instance.attachments.create(file=attachment.read())

Looks pretty simple to me.

class Attachment(Model):
    file = FileField()

class Email(Model):
    headers = TextField()
    text = TextField()
    html = TextField()
    to = TextField()
    cc = TextField()
    subject = TextField()
    dkim = JSONField()
    SPF = JSONField()
    envelope = JSONField()
    charsets = CharField(max_length=255)
    spam_score = FloatField()
    spam_report = TextField()
    attachments = ManyToManyField(Attachment) 

EmailForm(ModelForm)
    attachments = IntegerField()
    class Meta:
        model = Email
        exclude = 'attachments'

@requires_POST
def sendgrid_email_reciever(request):
    form = EmailForm(request.POST)
    if form.is_valid()
        form.instance.save()
        for i in range(1,form.cleaned_data.['attachments']+1):
            attachment = request.FILES['attachment%d' % i]
            form.instance.attachments.create(file=attachment.read())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文