When using Web API to send messages with attachments, it's necessary to upload those files in temporary directory of WebMail 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:
2. Uploading email message into specific folder:
3. Uploading file into Files storage:
4. Uploading contacts into address book:
5. Uploading calendar:
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:
$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);
Note that any existing file with the same name will be overwritten automatically.
"TempName":"upload-post-dcbcbd6b29caf4c0dbbc464a1b86e94a", // temporary name used when saving and sending message
"Hash":"Dmpd0arW8Qbc1KKintwtn50z8aPhYhl1Y0ZL6kOSgQV4f_rN9pDIj9XhkDwzfHi75X4i5Crzpoxc-9N93FDwG7wOHAcokoU7RdG3c66yIqkjlN5TQIEKuKCoGPVvH32LobMav8I6mD8FiqEguDZiq9A9XjN_e9jqaoeKalaXNxWj952gBs_Q7_hcYulPCZWndSojv7849RWQ6PzPwDr-GvEKJOeGMJqR" // needed to view or download file
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.