Sending email with google engine from a remote host, how do I configure a file?

I use the Google engine to send emails based on https://github.com/godsid/appEngineSendMail

so I make a curl request from my remote host and it works.

but how can I attach files to appengine?

these are my curl post_fields

$fields = array(
                'to' => urlencode($to),
                'sender' => urlencode($from),
                'body' => urlencode($body),
                'subject' => urlencode($subject),
                'key' => urlencode('****')
                );

$fields['attachments']= array("@". $_FILES['attachment']['tmp_name']);

I searched for an answer within 2 days ... any help or advice is appreciated

+4
source share
2 answers

The problem was that I was url_encoding an array of fields, doing this so that cURL would not notice @filename and attach the file to the request.

so I had to make a multipart request

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));

curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

python self.request.get(), , script github, ,

self.request.post [],

attachment = self.request.POST["attachment"] #actual attachment file
attachment_name = self.request.POST["attachment_name"] #string value of attahcment name sent from php side
message.attachments = [(attachment_name, attachment.value)]

* note self.request.get - , self.request.post -

, - :)

+3

. .

$fields['attachments'] = array(
    $_FILES['attachment']['name'] => file_get_contents($_FILES['attachment']['tmp_name'])
);
+2

All Articles