Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Introduction 

Panel

This example allows you to convert message to various formats using Aspose.Email for Cloud API in your applications. You can use our REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more.

Resource

Panel

The following Aspose.Email for Cloud REST API resource has been used in the examples: Create Email.

REST Methods References

Panel

We're referring some common methods in the REST examples to perform general operations. These methods can be found at the following page: REST API Methods

REST Examples

Panel
Wiki Markup
{composition-setup}{composition-setup}
Wiki Markup
{deck:id=1}
Wiki Markup
{card:label=C#}
Code Block
// Initialize variables being used
string appSid = "Get it from https://cloud.aspose.com";
string appKey = "Get it from https://cloud.aspose.com";

string name = "email-sample.mht";
EmailFormat format = EmailFormat.Msg;
string folder = "Email";
string outPath = "EmailOutput/email-output.msg";
string storage = string.Empty;

// Build URI to perform request
string apiUrl = string.Format(@"email/{0}?format={1}&storage={2}&folder={3}&outPath={4}", name, format, storage, folder, (outPath.Contains(@":\") ? string.Empty : outPath));

if (!string.IsNullOrEmpty(outPath) && Directory.Exists(Path.GetDirectoryName(outPath)))
{
	using (Stream responseStream = ServiceController.GetStream(apiUrl, appSid, appKey))
	using (Stream file = File.OpenWrite(outPath))
	{
		ServiceController.CopyStream(responseStream, file);
	}
}
else
{
	ServiceController.Get(apiUrl, appSid, appKey);
}
Wiki Markup
{card}
Wiki Markup
{card:label=VB.NET}
Code Block
' Initialize variables being used
Dim appSid As String = "Get it from https://cloud.aspose.com"
Dim appKey As String = "Get it from https://cloud.aspose.com"

Dim name As String = "email-sample.mht"
Dim format As EmailFormat = EmailFormat.Msg
Dim folder As String = "Email"
Dim outPath As String = "EmailOutput/email-output.msg"
Dim storage As String = String.Empty

' Build URI to perform request
Dim apiUrl As String = String.Format("email/{0}?format={1}&storage={2}&folder={3}&outPath={4}", name, format, storage, folder, (If(outPath.Contains(":\"), String.Empty, outPath)))

If Not String.IsNullOrEmpty(outPath) AndAlso Directory.Exists(Path.GetDirectoryName(outPath)) Then
	Using responseStream As Stream = ServiceController.GetStream(apiUrl, appSid, appKey)
		Using file As Stream = File.OpenWrite(outPath)
			ServiceController.CopyStream(responseStream, file)
		End Using
	End Using
Else
	ServiceController.Get(apiUrl, appSid, appKey)
End If
Wiki Markup
{card}
Wiki Markup
{card:label=Java}
Code Block
import java.io.*;
import com.aspose.cloud.common.Utils;
import com.aspose.cloud.storage.Folder;

String appSID = "...";
String appKey = "...";

String method = "GET";
String requestUrl = "http://api.aspose.com/v1.1/email/Sample1.eml?format=mht";
String outputFile = "Sample1.mht";

String outputFilePath = new File(System.getProperty("user.dir"), outputFile).getPath();
String signedUrl = Utils.Sign(requestUrl, appKey, appSID);

InputStream responseStream = Utils.ProcessCommand(signedUrl, method);
Folder.SaveStreamToFile(outputFilePath, responseStream);
responseStream.close();
System.out.println("File saved: " + outputFilePath);

Wiki Markup
{card}
Wiki Markup
{card:label=PHP}
Code Block
use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Utils;

AsposeApp::$appSID = "...";
AsposeApp::$appKey = "...";

$method = "GET";
$base_url = "http://api.aspose.com/v1.1";
$request_url = "$base_url/email/Sample1.eml?format=mht";
$output_file = getcwd() . "/Sample1.mht";
$signed_url = Utils::sign($request_url);

$response = Utils::processCommand($signed_url, $method, "", "");
file_put_contents($output_file, $response);
echo "File saved: $output_file\n";

Wiki Markup
{card}
Wiki Markup
{card:label=Ruby}
Code Block
app_sid = "..."
app_key = "..."
request_url = "http://api.aspose.com/v1.1/email/Sample1.eml?format=mht"
output_file = File.join(Dir.pwd, "Sample1.mht")

Aspose::Cloud::Common::AsposeApp.new(app_sid, app_key)
signed_url = Aspose::Cloud::Common::Utils.sign(request_url)

response = RestClient.get(signed_url)
File.open(output_file, "wb") { |file| file.write(response) }
puts "File saved: #{output_file}"

Wiki Markup
{card}
Wiki Markup
{card:label=Python}
Code Block
import os.path
from aspose.cloud.common import *

AsposeApp.app_sid = "..."
AsposeApp.app_key = "..."

method = "GET"
request_url = "http://api.aspose.com/v1.1/email/Sample1.eml?format=mht"
output_file = "Sample1.mht"
output_file_path = os.path.join(os.getcwd(), output_file)
signed_url = Utils.sign(Utils(), request_url)

response = Utils.process_command(Utils(), signed_url, method, "", "")
Utils.save_file(Utils(), response, output_file_path)
print "File saved:", output_file_path

Wiki Markup
{card}
Wiki Markup
{card:label=Perl}
Code Block
languageperl
 
Wiki Markup
{card}
Wiki Markup
{card:label=Node.js}
Code Block
languagejavascript
var appSID = '...';
var appKey = '...';
var base_url = 'http://api.aspose.com/v1.1/';
var fs = require('fs');

var method = 'GET';
var request_url = base_url + 'email/Sample1.eml?format=mht';
var output_file = 'Sample1.mht';

ProcessCommandContent(
	method,
	Sign(request_url, appSID, appKey),
	null,
	function(buffer) {
		fs.writeFileSync(output_file, buffer);
	}
);

Wiki Markup
{card}
Wiki Markup
{card:label=C++}
Code Block
languagecpp
std::string app_sid("...");
std::string app_key("...");
std::string base_url("http://api.aspose.com/v1.1/");

std::string method = "GET";
std::string request_url = base_url + "email/Sample1.eml?format=mht";
std::string signed_url = sign(request_url, app_sid, app_key);
std::string output_file = "Sample1.mht";

std::ofstream output_fstream;
output_fstream.open(output_file, std::ofstream::binary);

process_command(method, signed_url, output_fstream);

output_fstream.close();

std::cout << "File saved: " << output_file << std::endl;

Wiki Markup
{card}
Wiki Markup
{card:label=Android}
Code Block
AsposeApp.setAppKeyAndAppSID("Get it from https://cloud.aspose.com", "Get it from https://cloud.aspose.com")
AsposeApp.setBaseProductURI("http://api.aspose.com/v1.1");

String EMAIL_URI = AsposeApp.BASE_PRODUCT_URI + "/email/";

//build URL
String strURL = EMAIL_URI + Uri.encode("Message.msg") + "?format=" + "eml";
//sign URL
String signedURL = Utils.sign(strURL);
InputStream responseStream = Utils.processCommand(signedURL, "GET");

//Save file on Disk
String outFilePath = Utils.saveStreamToFile(responseStream, "Message.eml");

Wiki Markup
{card}
Wiki Markup
{card:label=Objective C (iOS)}
Code Block
[ASPOSEApp setAppKey:@"Get it from https://cloud.aspose.com" andAppSID:@"Get it from https://cloud.aspose.com"];
[ASPOSEProduct setBaseProductUri:@"http://api.aspose.com/v1.1"];

NSString *EMAIL_URI = [[ASPOSEProduct baseProductUri] stringByAppendingString:@"/email/"];

NSString *fileName = @"Self Assessment.eml";

//build URL
NSString *strURL = [NSString stringWithFormat:@"%@%@?format=%@", EMAIL_URI,
                    [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], @"msg"];
//sign URL
NSString *signedURL = [ASPOSEUtils sign:strURL];

NSData *responseData = [ASPOSEUtils processCommand:signedURL httpMethod:@"GET"];

//Save file on Disk
NSString *outFilePath = [ASPOSEFolder saveFile:responseData withName:@"Self Assessment.msg"];

Wiki Markup
{card}
Wiki Markup
{deck}

SDK Source

The Aspose for Cloud SDKs can be downloaded from the following page: Available SDKs

cURL Example

Panel
bgColor#FFFFFF
Expand
titleRequest
Code Block
curl -v "http://api.aspose.cloud/v1.1/email/email_test.eml?format=msg&appSID=XXXX&signature=XXXX" \
     -X GET \
     -H "Content-Type: application/json" \
     -H "Accept: application/json"
Expand
titleResponse
Code Block
Converted File

SDK Examples

Panel
titleConvert email to other formats
Expand
titleC#
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-DotNET-CSharp-Email-ConvertToOtherFormat-1.cs"></script>
Expand
titleJava
HTML
<script src="https://gist.github.com/aspose-email/10428737982c525bf33b54ad9c27b707.js?file=Examples-JAVA-SDK-src-main-java-com-aspose-email-cloud-examples-working-ConvertEmailOtherFormats-ConvertEmailOtherFormats.java"></script>
Expand
titlePHP
HTML
<script src="https://gist.github.com/a052f420f51722082cbb70d5e8d0f339.js?file=Examples-PHP-Email-GetDocumentWithFormat-.php"></script>
Expand
titleRuby
HTML
<script src="https://gist.github.com/aspose-email/3f41448648db89803193189f274722fa.js?file=Examples-Ruby-Email-get_email_in_specified_format-.rb"></script>
Expand
titlePython
HTML
<script src="https://gist.github.com/aspose-email/13478a90f198800bfcdafa983dbd0fcd.js?file=ConvertEmailToOtherFormat.py"></script>
Expand
titleNode.js
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Node.js-Email-ConvertToOtherFormat-1.js"></script>
Expand
titleAndroid
HTML
<script src="https://gist.github.com/aspose-email/95a576636fc5c03e126e2617c83ce117.js?file=Examples-Android-app-src-main-java-com-aspose-email-cloud-examples-working-ConvertEmailOtherFormats-ConvertEmailOtherFormats.java"></script>
Expand
titleObjective C
HTML
<script src="https://gist.github.com/1779f6b192c8df02d5c083a6abedfb62.js?file=Examples-Objective C-Aspose.Email-Aspose.Email-Email-Email-GetDocumentWithFormat.m"></script>
Expand
titlePerl
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Perl-Email-ConvertToOtherFormat-1.pl"></script>