@@ -6,16 +6,15 @@ image: http
66
77# CloudMailin Send Email Message API
88
9- In order to send an email via API you can create a POST request to the Email
10- Message endpoint:
9+ To send an email via the API, create a POST request to the Email Message endpoint:
1110
1211` POST ` : ` https://api.cloudmailin.com/api/v0.1/{SMTP_USERNAME}/messages ` .
1312
14- Sending email via HTTP POST can be done via one of two methods :
13+ There are several ways to send email :
1514
16- * If a [ client library] is available for your Programming Language / Framework
17- you can use a client library; Alternatively;
18- * you can make an HTTP POST to our API manually to send the email
15+ * Use a [ client library] if one is available for your language or framework
16+ * Make an HTTP POST with a [ JSON message ] ( #json-message ) — CloudMailin will construct the email for you
17+ * Make an HTTP POST with a [ raw RFC822 message ] ( #raw-message ) — useful if you're building the email yourself or migrating from another provider
1918
2019## Client Libraries
2120
@@ -38,101 +37,61 @@ development.
3837
3938## Sending Email with an API Call
4039
41- If your Language / Framework isn't listed above then you can always make a
40+ If your language or framework isn't listed above you can make a
4241request directly to the Outbound Email API.
4342
44- You can also use any language / framework via [ SMTP] .
43+ You can also send email using any language or framework via [ SMTP] .
4544
4645### Authentication
4746
48- Authentication relies on your username and password from you SMTP credentials.
47+ Authentication relies on your username and password from your SMTP credentials.
4948You can find your SMTP credentials for both live and test accounts on the
5049[ SMTP Accounts] page. Your SMTP username is part of the path used to make the
51- SMTP request: ` POST ` :
50+ request: ` POST ` :
5251` https://api.cloudmailin.com/api/v0.1/[SMTP_USERNAME]/messages `
5352
5453You then need to send your SMTP API Token.
5554Authentication is via the Bearer token in the Authorization header as follows:
5655` Authorization: Bearer API_TOKEN ` .
5756
58- > This documentation is currently a work in progress. If you need help sending
59- > via the API please feel free to contact us, alternatively you may wish to use
60- > [ SMTP] , which is fully functional.
57+ ## JSON Message
6158
62- ## Email Messages Endpoint Example
59+ The simplest way to send email is to POST a JSON object with the message fields.
60+ CloudMailin will construct the email for you.
6361
64- A full example POST can be seen below:
62+ ### Example
6563
6664``` json
67- {
68- "from" : " Sender Name <sender@example.com>" ,
69- "to" : [
70- " Recipient <recipient@example.com>" ,
71- " Another <another@example.com>"
72- ],
73- "test_mode" : false ,
74- "subject" : " Hello from CloudMailin 😃" ,
75- "tags" : [
76- " api-tag" ,
77- " cloudmailin-tag"
78- ],
79- "plain" : " Hello Plain Text" ,
80- "html" : " <h1>Hello Html</h1>" ,
81- "headers" : {
82- "x-api-test" : " Test" ,
83- "x-additional-header" : " Value"
84- },
85- "attachments" : [
86- {
87- "file_name" : " pixel.png" ,
88- "content" : " iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP0rdr1HwAFHwKCk87e6gAAAABJRU5ErkJggg==" ,
89- "content_type" : " image/png" ,
90- "content_id" : null
91- }
92- ]
93- }
65+ <%= render_api_example("components/schemas/Message") %>
9466```
9567
96- Below you can see an explanation of the [ fields] ( #fields ) , how to add
97- [ attachments] ( #attachments ) and how to set custom [ headers] ( #headers ) .
98-
9968### Fields
10069
101- The API allows sending with the following fields:
102-
10370| Field | Type | Description |
10471| ---------------| ---------| ---------------------------------------------------------------------|
105- <%= render_api_fields("components/schemas/MessageCommon/properties/", include_readonly: false) %>
106- <%= render_api_fields("components/schemas/Message/allOf/1/properties", 'plain', 'html') %>
72+ <%= render_api_fields("components/schemas/Message", include_readonly: false, except: %w[ headers attachments] ) %>
10773| ` headers ` | object | See the [ headers section] ( #headers )
108- | ` attachments ` | Arrary of attachment objects | See the [ attachments section] ( #attachments )
74+ | ` attachments ` | array of attachment objects | See the [ attachments section] ( #attachments )
10975
11076### Attachments
11177
112- Attachments are slightly more complicated and require the following fields
78+ Attachments require the following fields:
11379
11480| Field | Type | Description |
11581| ---------------| ---------| ---------------------------------------------------------------------|
116- <%= render_api_fields("components/schemas/MessageAttachment/properties/ ") %>
82+ <%= render_api_fields("components/schemas/MessageAttachment") %>
11783
118- For example this attaches a one-pixel image (Base64 encoded) :
84+ For example:
11985
12086``` json
121- "attachments" : [
122- {
123- "file_name" : " pixel.png" ,
124- "content" : " iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP0rdr1HwAFHwKCk87e6gAAAABJRU5ErkJggg==" ,
125- "content_type" : " image/png" ,
126- "content_id" : null
127- }
128- ]
87+ <%= render_api_example("components/schemas/MessageAttachment") %>
12988```
13089
13190### Headers
13291
133- Headers are not required as the subject, to and from headers will be set. However, if you need to
134- specify additional headers you can pass them as an object.
135- The key is the header name and the value is expected to be a string a string value :
92+ Headers are not required as the subject, to and from headers will be set automatically.
93+ If you need to specify additional headers you can pass them as an object.
94+ The key is the header name and the value is expected to be a string:
13695
13796``` json
13897"headers" : {
@@ -141,6 +100,24 @@ The key is the header name and the value is expected to be a string a string val
141100}
142101```
143102
103+ ## Raw Message
104+
105+ If you already have a constructed RFC822 email you can send it directly using
106+ the ` raw ` field instead of ` plain ` /` html ` . This is useful if you're generating
107+ emails with your own library or migrating from another provider.
108+
109+ ### Example
110+
111+ ``` json
112+ <%= render_api_example("components/schemas/RawMessage") %>
113+ ```
114+
115+ ### Fields
116+
117+ | Field | Type | Description |
118+ | ---------------| ---------| ---------------------------------------------------------------------|
119+ <%= render_api_fields("components/schemas/RawMessage", include_readonly: false, except: %w[ headers attachments] ) %>
120+
144121[ Client Library ] : #client-libraries
145122[ SMTP Accounts ] : https://www.cloudmailin.com/outbound/senders
146123[ SMTP ] : < %= url_to_item('/outbound/sending_email_with_smtp/') % >
0 commit comments