Sending a Message with an Attachment
POST https://api.expresspigeon.com/messages
Request Parameters
Request parameters are the same as when sending a single message without attachments.
Limitations are: maximum three attachments, each under 10mb in size.
Example Request
1
2
3
4
5
6
7
8
9
10
11
| curl -X POST https://api.expresspigeon.com/messages \
-H "Content-type: multipart/form-data" \
-H "X-auth-key: 00000000-0000-0000-0000-000000000000"\
-F template_id=123\
-F reply_to='john@doe.com'\
-F from='John Doe'\
-F to='jane@doe.com'\
-F subject='two attachments'\
-F merge_fields='{"first_name": "Jane"}'\
-F attachment=@attachment1.txt\
-F attachment=@attachment2.txt
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| import org.javalite.http.Http;
import static org.javalite.common.Collections.map;
import static org.javalite.common.JsonHelper.toJsonString;
import static org.javalite.common.JsonHelper.toMap;
String response = Http.multipart("https://api.expresspigeon.com/messages")
.header("X-auth-key", AUTH_KEY)
.file("attachment", "/path/to/attachment1.txt")
.file("attachment", "/path/to/attachment2.txt")
.field("template_id", "123")
.field("reply_to", "john@doe.com")
.field("from", "John Doe")
.field("to", "jane@doe.com")
.field("subject", "two attachments")
.field("merge_fields", toJsonString(map("first_name", "Jane")))
.text();
Map<String, Object> result = toMap(response);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| $attachement1 = file_get_contents('/path/to/attachement1.txt');
$attachement2 = file_get_contents('/path/to/attachement2.txt');
$eol = "\r\n";
$data = '';
$mime_boundary=md5(time());
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="template_id"' . $eol . $eol;
$data .= "123" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="reply_to"' . $eol . $eol;
$data .= "john@doe.com" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="from"' . $eol . $eol;
$data .= "John Doe" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="to"' . $eol . $eol;
$data .= "jane@doe.com" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="subject"' . $eol . $eol;
$data .= "two attachments" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="view_online"' . $eol . $eol;
$data .= "true" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="suppress_address"' . $eol . $eol;
$data .= "true" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="click_tracking"' . $eol . $eol;
$data .= "false" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="merge_fields"' . $eol . $eol;
$data .= json_encode(array('first_name' => 'Jane')) . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="attachment"; filename="attachment1.txt"' . $eol;
$data .= 'Content-Type: text/plain' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= $attachement1 . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol;
$data .= 'Content-Disposition: form-data; name="attachment"; filename="attachment2.txt"' . $eol;
$data .= 'Content-Type: text/plain' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= $attachement2 . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol;
$params = array('http' => array(
'method' => 'POST',
'header' => 'X-auth-key: 00000000-0000-0000-0000-000000000000' . $eol .
'Content-Type: multipart/form-data; boundary=' . $mime_boundary . $eol,
'content' => $data
));
$ctx = stream_context_create($params);
$response = file_get_contents('https://api.expresspigeon.com/messages', FILE_TEXT, $ctx);
|
1
2
3
4
5
6
7
8
9
10
11
| require 'expresspigeon-ruby'
MESSAGES = ExpressPigeon::API.messages.auth_key(ENV['AUTH_KEY'])
puts MESSAGES.send_message(
390243, #template_id
'john@example.com', #to
'jane@example.com', #reply_to
"Jane Doe", #from_name
"Lets go out for dinner?", #subject
{first_name: 'John', meeting_place: 'Downtown'}, #merge_fields
%W{attachments/attachment1.txt attachments/example.ics} #files as attachments
)
|
1
2
3
4
5
6
7
| from expresspigeon import ExpressPigeon
api = ExpressPigeon()
response = api.messages.send_message_attachment(template_id=123, attachments=["path/to/attachment1.txt", "path/to/attachment2.txt"],
to="jane@example.net",
reply_to="john@example.net", from_name="John", subject="Dinner served",
merge_fields={"first_name": "John", "menu": "<table><tr><td>Burger:</td></tr><tr>$9.99<td></td></tr></table>"})
|
The code above shows how to include attachments. The paths to files can be absolute, or relative (as in this example).
Example Response
1
2
3
4
5
6
| {
"status": "success",
"code": 200,
"id": 1,
"message": "email queued"
}
|
In the call above, the id
represents an ID of a message that was sent. You can use this value in order to get a report on the status of this message. Please, see below on how to retrieve such a report.