# enumerate through all attachments in the message and save # them to disk with their original filenames: for attachment in request.files.values(): attachment.filename data = attachment.stream.read() with open(attachment.filename, "w") as f: f.write(data)
attachment-x | string | attached file ('x' stands for number of the attachment). Attachments are handled as file uploads, encoded as multipart/form-data. |
content-id-map | string | JSON-encoded dictionary which maps Content-ID (CID) of each attachment to the corresponding attachment-x parameter. This allows you to map posted attachments to tags like <img src='cid'> in the message body. |
[sender] => mdaytrades@gmail.com
[subject] => SUBJECT OF MESSAGE
[from] => mdaytrades <mdaytrades@gmail.com>
[Received] => from [192.168.0.12] (CPE0026f336fc30-CM0026f336fc2d.cpe.net.cable.rogers.com. [99.233.238.184]) bymx.google.com with ESMTPS id wn10sm4453782igb.2.2013.03.20.03.01.59 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Mar 2013 03:02:00 -0700 (PDT)
[X-Envelope-From] => <mdaytrades@gmail.com>
[Dkim-Signature] => v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:subject:date:references:to:message-id :mime-version:x-mailer; bh=z2IoCinGNl4lOcyJgDRZOTqqTbEmOXG+ftlhXIfSivI=; b=G2IaZ6gPn9GtugTTrIErSWuIyo4Ad9uiUcsp/XpoxXQFBJ5T0CEwNznldIXI15vQ4Q ND8G6wf1PGRWKURTD8nSb0TRSFInBqImAW5t3KnhXKt/WGEVNOajwfwTR3m2OiryZkG8 C5qA8YHNWQHS8j9rzXP0RNxY3T8MN7YmtrWEdcybMpfgxFFjFdyB0IEF5+KDhaJ0Nc/u oCtdrsXU1rVZNp52uqdiCHrR/7Ca7rAwMP3rxQx6X7yXiBcSqu2Lp9pSmwkHhWnFoJcn WnLWbEVRQgsg+qKy8OJHIexEvdJa7Bwo/nSuPs+IIWyFKhQzLOqb8dXgDcDsuqVV2oPt 8BKw==
[X-Received] => by 10.42.88.145 with SMTP id c17mr13130362icm.47.1363773721513; Wed, 20 Mar 2013 03:02:01 -0700 (PDT)
[Return-Path] => <mdaytrades@gmail.com>
[From] => mdaytrades <mdaytrades@gmail.com>
[Content-Type] => multipart/alternative; boundary="Apple-Mail=_EC882749-B764-43DB-9769-3F4850B978F3"
[Subject] => SUBJECT OF MESSAGE
[Date] => Wed, 20 Mar 2013 06:02:00 -0400
[References] => <8A01B27E-CD7D-4599-B1C5-F87BF874624C@gmail.com>
[To] => "testreceiver@ducksoup.mailgun.org" <testreceiver@ducksoup.mailgun.org>
[Message-Id] => <9385EC89-5462-4BA1-93B9-9E4E8BEC1BDA@gmail.com>
[Mime-Version] => 1.0 (Mac OS X Mail 6.3 \(1503\))
[X-Mailer] => Apple Mail (2.1503)
[X-Mailgun-Incoming] => Yes
[message-headers] => [["Received", "by luna.mailgun.net with SMTP mgrt 8784990917749; Wed, 20 Mar 2013 10:02:02 +0000"], ["X-Envelope-From", "<mdaytrades@gmail.com>"], ["Received", "from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) bymxa.mailgun.org with ESMTP id 51498919.7f7908037770-in1; Wed, 20 Mar 2013 10:02:01 -0000 (UTC)"], ["Received", "by mail-ie0-f180.google.comwith SMTP id a11so1597996iee.39 for <testreceiver@ducksoup.mailgun.org>; Wed, 20 Mar 2013 03:02:01 -0700 (PDT)"], ["Dkim-Signature", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:content-type:subject:date:references:to:message-id :mime-version:x-mailer; bh=z2IoCinGNl4lOcyJgDRZOTqqTbEmOXG+ftlhXIfSivI=; b=G2IaZ6gPn9GtugTTrIErSWuIyo4Ad9uiUcsp/XpoxXQFBJ5T0CEwNznldIXI15vQ4Q ND8G6wf1PGRWKURTD8nSb0TRSFInBqImAW5t3KnhXKt/WGEVNOajwfwTR3m2OiryZkG8 C5qA8YHNWQHS8j9rzXP0RNxY3T8MN7YmtrWEdcybMpfgxFFjFdyB0IEF5+KDhaJ0Nc/u oCtdrsXU1rVZNp52uqdiCHrR/7Ca7rAwMP3rxQx6X7yXiBcSqu2Lp9pSmwkHhWnFoJcn WnLWbEVRQgsg+qKy8OJHIexEvdJa7Bwo/nSuPs+IIWyFKhQzLOqb8dXgDcDsuqVV2oPt 8BKw=="], ["X-Received", "by 10.42.88.145 with SMTP id c17mr13130362icm.47.1363773721513; Wed, 20 Mar 2013 03:02:01 -0700 (PDT)"], ["Return-Path", "<mdaytrades@gmail.com>"], ["Received", "from [192.168.0.12] (CPE0026f336fc30-CM0026f336fc2d.cpe.net.cable.rogers.com. [99.233.238.184]) bymx.google.com with ESMTPS id wn10sm4453782igb.2.2013.03.20.03.01.59 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Mar 2013 03:02:00 -0700 (PDT)"], ["From", "mdaytrades <mdaytrades@gmail.com>"], ["Content-Type", "multipart/alternative; boundary=\"Apple-Mail=_EC882749-B764-43DB-9769-3F4850B978F3\""], ["Subject", "SUBJECT OF MESSAGE"], ["Date", "Wed, 20 Mar 2013 06:02:00 -0400"], ["References", "<8A01B27E-CD7D-4599-B1C5-F87BF874624C@gmail.com>"], ["To", "\"testreceiver@ducksoup.mailgun.org\" <testreceiver@ducksoup.mailgun.org>"], ["Message-Id", "<9385EC89-5462-4BA1-93B9-9E4E8BEC1BDA@gmail.com>"], ["Mime-Version", "1.0 (Mac OS X Mail 6.3 \\(1503\\))"], ["X-Mailer", "Apple Mail (2.1503)"], ["X-Mailgun-Incoming", "Yes"]]
[timestamp] => 1363773724
[token] => 48km59sauktayd45fziefvfs6ndfalfh5kr0emkroa0g78irt8
[signature] => d525e5b382f4182d03266b80995019c1e300d2f643d1d242a6552c04650d84f0
[attachment-count] => 1
[body-plain] => > BODY OF MESSAGE. MESSAGE SHOULD HAVE 1 ATTACHMENT
[body-html] => <html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>BODY OF MESSAGE. MESSAGE SHOULD HAVE 1 ATTACHMENT</div></div></blockquote><img height="241" width="240" apple-width="yes" apple-height="yes" id="821a76ff-2351-4833-a22c-c3a2121bbbf4" src="cid:99098D0F-79DD-44A9-AC75-B65899C122BA@vlan1.phub.net.cable.rogers.com"></div></body></html>
[stripped-html] => <html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><img height="241" width="240" apple-width="yes" apple-height="yes" id="821a76ff-2351-4833-a22c-c3a2121bbbf4" src="cid:99098D0F-79DD-44A9-AC75-B65899C122BA@vlan1.phub.net.cable.rogers.com"></div></body></html>
[stripped-text] => > BODY OF MESSAGE. MESSAGE SHOULD HAVE 1 ATTACHMENT
[content-id-map] => {"<99098D0F-79DD-44A9-AC75-B65899C122BA@vlan1.phub.net.cable.rogers.com>": "attachment-1"}
)
Sent from my iPad
Show the result of debug ($this->request->data);That will either answer the question for you or show the data isn't there to be accessed.--AD
On Tuesday, 19 March 2013 18:26:15 UTC+1, MDay wrote:hi there - hoping someone can help me with a simple issue I have having with retrieving data from an HTTP Post. I am using mailgun to post an email message to a simple method in my application... Everything is working correctly except I can't get attachments out of the POST. I noticed that the encoding is set as multipart/form-data and the support guys at mailgun indicated I had to use $FILES to retrieve the data from the post. I am a bit of a newbie, so now I am lost..Here is what my current code looks like:$subject = $this->request->data('subject'); //THIS WORKS
$attachement_test1 = $this->request->data($_FILES['attachment-1']); //THIS DOESN'T WORK
$attachement_test2 = $this->request->data('attachment-1');//THIS DOESN'T WORK EITHER
$this->log("New Message");
$this->log($subject);
$this->log($attachement_test1);
$this->log($attachement_test2);
Snip from the mailgun docs:
attachment-x string attached file ('x' stands for number of the attachment). Attachments are handled as file uploads, encoded as multipart/form-data.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/Kn-xCR2Rjt8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment