MailSuite Pro documentation

Uploading files via PUT

When using Web API to send messages with attachments, it's necessary to upload those files in temporary directory of MailSuite Pro first.

API offers a couple of ways for uploading files - however, those methods require using a web browser and cannot be used in desktop program, mobile app etc. In those cases, starting from version 7.6.3 of }, files can be uploaded using PUT method.

Similarly to uploading attachments, the same approach is used for uploading other kinds of data.

1. Uploading attachment:

PUT http://webmail.domain.com/index.php?Upload/Attachment/AccountID/FileName

2. Uploading email message into specific folder:

PUT http://webmail.domain.com/index.php?Upload/Message/AccountID/Folder-FullName/Name.eml

3. Uploading file into Files storage:

PUT http://webmail.domain.com/index.php?Upload/File/Path/FileName

4. Uploading contacts into address book:

PUT http://webmail.domain.com/index.php?Upload/Contacts/FileName.vcf

5. Uploading calendar:

PUT http://webmail.domain.com/index.php?Upload/Calendars/CalendarID/FileName.ics

In all the cases, Auth-Token header needs to be sent through, containing authentication token. Body of the request represents content to be uploaded.

This approach can be used in applications written in any programming language. The sample code below is written in PHP. The code assumes that the following values are defined already:

* $iAccountID

* $sFolderFullName

* $sFileName

* $sToken

$sFilePath = 'mail.eml';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://webmail.domain.com/index.php?Upload/Message/'.$iAccountID.'/'.$sFolderFullName.'/'.$sFileName.'.eml');
curl_setopt($ch, CURLOPT_PUT, 1);

$rFile = fopen($sFilePath, 'r');

curl_setopt($ch, CURLOPT_INFILE, $rFile);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($sFilePath));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Auth-Token: '.$sToken));
$curlResponse = curl_exec ($ch);
fclose($rFile);

Note that any existing file with the same name will be overwritten automatically.

Sample response:

{
  "Action":"UploadAttachment",
  "AccountID":1,
  "Result":
  {
    "Attachment":
    {
      "Name":"apple-icon.png",
      "TempName":"upload-post-dcbcbd6b29caf4c0dbbc464a1b86e94a", // temporary name used when saving and sending message
      "MimeType":"image/png",
      "Size":576,
      "Iframed":false,
      "Hash":"Dmpd0arW8Qbc1KKintwtn50z8aPhYhl1Y0ZL6kOSgQV4f_rN9pDIj9XhkDwzfHi75X4i5Crzpoxc-9N93FDwG7wOHAcokoU7RdG3c66yIqkjlN5TQIEKuKCoGPVvH32LobMav8I6mD8FiqEguDZiq9A9XjN_e9jqaoeKalaXNxWj952gBs_Q7_hcYulPCZWndSojv7849RWQ6PzPwDr-GvEKJOeGMJqR" // needed to view or download file
    }
  },
  "@Time":0.14194798469543
}

As you can see, the response returned is presented identically to uploading files via form or AJAX. The files are uploaded to temporary directory, and temporary filenames are assigned for them - while actual filename corresponds to name of the file uploaded.

Once the attachments are uploaded, you can proceed with sending a message. You will need to supply both Name and TempName for all the attachments you add. Note that temporary files are automatically removed in 24 hours after uploading them.