带有sinatra的Mandrill API电子邮件队列



尝试获取表单以向Mandrill api发送电子邮件。我的电子邮件一直在排队,无法发送。

post '/my-handling-form-page' do
    m = Mandrill::API.new
    message = {
        :subject => "Hello from the Mandrill API",
        :from_name => "#{params[:name]} #{params[:email]}",
        :text => "Hi message how are you?",
        :to => [
            {
                :email => "anonymous@gmail.com",
                :name => "Recipient1"
             }
        ],
        :html => "<html>#{params[:msg]}</html>",
        :from_email => "anonymous@gmail.com"
    }
    sending = m.messages.send message
    puts sending
    erb :index
end

错误显示:{"电子邮件"=>"anonymous@gmail.com","status"=>"queued","_id"=>"216c30f42ee849e2a70528e3d4f9774f","reject_treason"=>nil}

我们将不胜感激。

来自Mandrill文档:

为什么传递的消息显示"已排队"?

Mandrill自动跟踪并记录我们收到的SMTP响应从收件人邮件服务器为您发送的每封电子邮件。一些成功已发送的电子邮件将在SMTP响应中包含"排队"符号例如250OK;以12345排队。电子邮件仍被发送到收件人如预期,但可能需要额外处理在它到达收件人的邮箱之前。例如,大多数时候Mandrill发送电子邮件的速度远远快于收件人服务器接受或处理它。在许多情况下ISP或收件人服务器的总体电子邮件流量会影响他们很快就能接收和处理您的电子邮件。

您的代码似乎很好。看起来收件人的服务器可能有问题。

来自Mandrill的响应邮件:

谢谢你伸出援手。在这种情况下,传递给Mandrill的API调用似乎包含多个无效参数-但是,由于您还在该API调用中向我们传递了一个附件数组,因此您不会看到指示该调用为无效API调用的响应。

每当Mandrill收到附件时,我们总是会返回"排队"的响应,因为我们的系统会将该消息放在一边,以便在我们以任何其他方式处理附件之前扫描附件中的病毒/恶意软件。这意味着,如果API调用出现其他问题,则不会向您发出警报,并且它将"静默"失败。

看起来您已经包含了默认API文档中的几个参数,但这些参数旨在向用户展示这些参数将如何包含。

    **"subaccount"**: "customer-123",

    **"ip_pool"**: "Main Pool",

都会导致此API调用失败,因为您正在指定帐户中不存在的选项。我建议您仔细检查API代码并删除任何不使用的代码。作为参考,发送电子邮件所需的最低API调用如下:{ "message": { "html": "<html content>", "subject": "<subject>", "from_email": "<sender email address>", "from_name": "<sender name>", "to": [ { "email": "<recipient email address>", "name": "<recipient name>", "type": "to" } ], "headers": { "Reply-To": "<reply-to address>" } }, "async": false, "ip_pool": null, "send_at": null, "key": "<valid API key>" }

所以在这个有价值的回应之后,这对我来说是Django中的工作:)
def send_mail_msg(): import mandrill

try:
    mandrill_client = mandrill.Mandrill('xxxxxxxxxxxxxxx')
    message = {
        # 'attachments': [{'content': 'ZXhhbXBsZSBmaWxl',
        #                         'name': 'myfile.txt',
        #                         'type': 'text/plain'}],
               'auto_html': None,
               'auto_text': None,
               # 'bcc_address': 'message.bcc_address@example.com',
               'from_email': 'xxxxx@xxxx.com',
               'from_name': 'Example Name',
               'global_merge_vars': [{'content': 'merge1 content', 'name': 'merge1'}],
               'google_analytics_campaign': 'gaurav@nexthoughts.com',
               'google_analytics_domains': ['example.com'],
               # 'headers': {'Reply-To': 'message.reply@example.com'},
               'html': '<p>Example HTML content</p>',
               'images': [{'content': 'ZXhhbXBsZSBmaWxl',
                           'name': 'IMAGECID',
                           'type': 'image/png'}],
               'important': False,
               'inline_css': None,
               'merge': True,
               'merge_language': 'mailchimp',
               # 'merge_vars': [{'rcpt': 'recipient.email@example.com',
               #                 'vars': [{'content': 'merge2 content', 'name': 'merge2'}]}],
               'metadata': {'website': 'www.example.com'},
               'preserve_recipients': None,
               'recipient_metadata': [{'rcpt': 'recipient.email@example.com',
                                       'values': {'user_id': 123456}}],
               'return_path_domain': None,
               'signing_domain': None,
               # 'subaccount': 'customer-123',
               'subject': 'example subject',
               'tags': ['password-resets'],
               'text': 'Example text content',
               'to': [{'email': 'xxxxx@xxxx.com',
                       'name': 'Recipient Name',
                       'type': 'to'}],
               'track_clicks': None,
               'track_opens': None,
               'tracking_domain': None,
               'url_strip_qs': None,
               'view_content_link': None}
    result = mandrill_client.messages.send(message=message, async=False, ip_pool='Main Pool')
    # send_at=str(datetime.datetime.now().time()))
    '''
    [{'_id': 'abc123abc123abc123abc123abc123',
      'email': 'recipient.email@example.com',
      'reject_reason': 'hard-bounce',
      'status': 'sent'}]
    '''
    return result
except mandrill.Error as e:  # Mandrill errors are thrown as exceptions
    print 'A mandrill error occurred: %s - %s' % (e.__class__, e)
    # A mandrill error occurred: <class 'mandrill.UnknownSubaccountError'> - No subaccount exists with the id 'customer-123'
    raise`

根据Mandrill api:

子账户

the unique id of a subaccount for this message - must already exist or will fail with an error.

(至少对我来说,删除该字段后测试就开始工作了)。Mandrill肯定应该改进他们的反应错误。

最新更新