【问题标题】:How do you parse a message from Sendgrid using their Parse API with Django?你如何使用他们的 Parse API 和 Django 解析来自 Sendgrid 的消息?
【发布时间】:2012-02-20 01:59:30
【问题描述】:

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

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

【问题讨论】:

    标签: python django parsing sendgrid


    【解决方案1】:

    对我来说看起来很简单。

    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())
    

    【讨论】:

      猜你喜欢
      • 2017-04-20
      • 2011-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-08
      • 1970-01-01
      相关资源
      最近更新 更多