Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Emails to PDF using REST API in PHP
// The following code example demonstrates how to add Client id and secret in the code
static $ClientId = '659fe7da-715b-4744-a0f7-cf469a392b73';
static $ClientSecret = 'b377c36cfa28fa69960ebac6b6e36421';
static $ApiBaseUrl = 'https://api.groupdocs.cloud';
static $MyStorage = '';
// This code example demonstrates how to convert Email attachments to PDF in PHP.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
// Create ConversionAPI instance
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
// Define convert settings
$settings = new GroupDocs\Conversion\Model\ConvertSettings();
$settings->setStorageName(self::$MyStorage);
$settings->setFilePath("Msg_with_attachments.msg");
$settings->setFormat("pdf");
$settings->setOutputPath("convertedAttachments.pdf");
// Define MSG load options
$loadOptions = new GroupDocs\Conversion\Model\MsgLoadOptions();
$loadOptions->setConvertAttachments(true);
// Create document request
$request = new GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings);
// Convert document
$response = $convertApi->convertDocument($request);
echo "Document converted successfully: ", $response[0]->getUrl();
// This code example demonstartes how to download PDF from the cloud.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
// Initialize API
$apiInstance = new GroupDocs\Conversion\FileApi($configuration);
// Create download request
$request = new GroupDocs\Conversion\Model\Requests\DownloadFileRequest("convertedEML.pdf", self::$MyStorage, null);
// Download file
$response = $apiInstance->downloadFile($request);
// This code example demonstrates how to convert EML to PDF in PHP.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
$configuration->setApiBaseUrl(self::$ApiBaseUrl);
// Create the new ConversionAPI instance
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
// Define convert settings
$settings = new GroupDocs\Conversion\Model\ConvertSettings();
$settings->setStorageName(self::$MyStorage);
$settings->setFilePath("sample.eml");
$settings->setFormat("pdf");
$settings->setOutputPath("convertedEML.pdf");
// Define EML load options
$loadOptions = new GroupDocs\Conversion\Model\EmlLoadOptions();
$loadOptions->setDisplayHeader(true);
$loadOptions->setDisplayFromEmailAddress(true);
$loadOptions->setDisplayToEmailAddress(true);
$loadOptions->setDisplayEmailAddress(true);
$loadOptions->setDisplayCcEmailAddress(true);
$loadOptions->setDisplayBccEmailAddress(true);
$settings->setLoadOptions($loadOptions);
// Define PDF convert options
$convertOptions = new GroupDocs\Conversion\Model\PdfConvertOptions();
$convertOptions->setCenterWindow(true);
$convertOptions->setMarginTop(50);
$convertOptions->setMarginLeft(50);
$convertOptions->setMarginRight(50);
$convertOptions->setMarginBottom(50);
$settings->setConvertOptions($convertOptions);
// Create convert request
$request = new GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings);
// Convert document
$response = $convertApi->convertDocument($request);
echo "Document converted successfully: ", $response[0]->getUrl();
// This code example demonstrates how to convert MSG to PDF in PHP.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
$configuration->setApiBaseUrl(self::$ApiBaseUrl);
// Create the new ConversionAPI instance
$convertApi = new GroupDocs\Conversion\ConvertApi($configuration);
// Define convert settings
$settings = new GroupDocs\Conversion\Model\ConvertSettings();
$settings->setStorageName(self::$MyStorage);
$settings->setFilePath("sample.msg");
$settings->setFormat("pdf");
$settings->setOutputPath("convertedMSG.pdf");
// Define MSG load options
$loadOptions = new GroupDocs\Conversion\Model\MsgLoadOptions();
$loadOptions->setDisplayCcEmailAddress(true);
$loadOptions->setDisplayBccEmailAddress(true);
$settings->setLoadOptions($loadOptions);
// Create convert request
$request = new GroupDocs\Conversion\Model\Requests\ConvertDocumentRequest($settings);
// Convert document
$response = $convertApi->convertDocument($request);
echo "Document converted successfully: ", $response[0]->getUrl();
// This code sample demonstrates how to upload an EML file to the cloud.
// Seting the configurations
$configuration = new GroupDocs\Conversion\Configuration();
$configuration->setAppSid(self::$ClientId);
$configuration->setAppKey(self::$ClientSecret);
// Initialize API
$apiInstance = new GroupDocs\Conversion\FileApi($configuration);
$file = "C:\\Files\\Conversion\\email\\sample.eml";
$request = new GroupDocs\Conversion\Model\Requests\UploadFileRequest("sample.eml", $file, self::$MyStorage, null);
$response = $apiInstance->uploadFile($request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment