Manage mail

This section gives examples for the following:

  • Send a mail with files
  • Send mail

Send a mail with files

This example demonstrates how to send a mail with an uploaded file to "user1@email.com", "user2@email.com".

Send mail

HTTP Method

POST

Request URL

https://{hostname}/rest/mail/actions/sendFile

Request Body

draft - 1 means create a draft mail. 0 - send the mail directly

{ "to": ["user1@email.com", "user2@email.com"], "cc": [], "bcc": [], "files": [1240], "subject": "Test mail subject", "body": "Test mail body", "draft": 0 }

Response

If the upload is initiated successfully, the response is a 201 Created status code. The response body contains a JSON representation of the mail, including a id property (256 in this sample request) that you can use as the mail ID for subsequent requests.

Example Request

Copy
   -X POST 'https://{hostname}/rest/mail/actions/sendFile?returnEntity=true' \
   -H 'Accept: application/json' \
   -H 'Content-Type: application/json' \
   -H 'X-Kiteworks-Version: 15' \
   -H 'Authorization: Bearer {access_token}' \
   -d '{"to": ["user1@email.com", "user2@email.com"], "files": [1240], "subject": "Test mail subject", "body": "Test mail body", "draft": 0}'

Example Response

Copy
{
    "emailPackageId": 197,
    "isRead": false,
    "variables": [
        {
            "variable": "HOST",
            "value": "{hostname}"
        },
        {
            "variable": "SENDER_EMAIL",
            "value": "{user@email.com}"
        },
        {
            "variable": "FILE_COUNT",
            "value": 1
        },
        {
            "variable": "EXPIRATION_DATE",
            "value": "Aug 28, 2020"
        },
        {
            "variable": "DOWNLOAD_LINK",
            "value": "https://{hostname}/w/Vo0FUmZryMDQVpsiGnEmDdd9F86kklnpyUNfQlNPCRe3m"
        },
        {
            "variable": "REGISTRATION_LINK",
            "value": "https://{hostname}/register?w=Vo0FUmZryMDQVpsiGnEmDdd9F86kklnpyUNfQlNPCRe3m"
        },
        {
            "variable": "SUBJECT",
            "value": "Test mail subject"
        },
        {
            "variable": "BODY",
            "value": "Test mail body"
        }
    ],
    "secureBody": false,
    "error": null,
    "senderId": 1,
    "templateId": 19,
    "id": 256,
    "date": "2020-05-20T07:25:15Z",
    "bucket": "outgoing",
    "isUserSent": true,
    "type": "original",
    "parentEmailId": null,
    "emailReturnReceipt": [],
    "isPreview": false,
    "recipients": [
        {
            "isDistributionList": false,
            "email": "user1@email.com",
            "type": 0,
            "userId": 1
        },
        {
            "isDistributionList": false,
            "email": "user2@email.com",
            "type": 0,
            "userId": 2
        }
    ],
    "subject": "Test mail subject",
    "deleted": false,
    "status": "queued",
    "watermark": null
}

Example Python Code

In the code example, the get_access_token() helper function returns the access token retrieved in the Authentication section using the authorization flow described there.

Copy
import requests
 
access_token = get_access_token()    
api_version = "15
hostname = "hostname.com"
 
headers = {
    "Accept": "application/json",
    "X-Kiteworks-Version": api_version,
    "Authorization": "Bearer {access_token}".format(access_token=access_token)
}
 
url = "https://{hostname}/rest/mail/actions/sendFile?returnEntity=true".format(
    hostname=hostname
)
data = {
    "to": ["user1@email.com", "user2@email.com"],
    "cc": [],
    "bcc": [],
    "files": [250],
    "subject": "Test mail subject",
    "body": "Test mail body",
    "draft": 0
}
response = requests.post(url=url, headers=headers, data=data)
mail = response.json()