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 set an email's property 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:properties

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";

/// <summary>
/// Set document property.
/// </summary>
/// <param name="name">File name. e.g. myEmail.msg</param>
/// <param name="propertyName">Property Name</param>
/// <param name="property">EmailProperty object</param>
/// <param name="folder">Folder path.</param>
/// <param name="storage">The document storage.</param>
string name; string propertyName; EmailProperty property; string folder; string storage = "";

// Build URI to perform request. ServiceController is located in Aspose.Cloud.Common in .NET SDK Source code available at http://goo.gl/BftpIi
string apiUrl = string.Format(@"email/{0}/properties/{1}?storage={2}&folder={3}", name, propertyName, storage, folder);

ServiceController.Put(apiUrl, appSid, appKey, JsonConvert.SerializeObject(property));
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"

''' <summary>
''' Set document property.
''' </summary>
''' <param name="name">File name. e.g. myEmail.msg</param>
''' <param name="propertyName">Property Name</param>
''' <param name="property">EmailProperty object</param>
''' <param name="folder">Folder path.</param>
''' <param name="storage">The document storage.</param>
Dim name As String
Dim propertyName As String
Dim [property] As EmailProperty
Dim folder As String
Dim storage As String = ""

' Build URI to perform request. ServiceController is located in Aspose.Cloud.Common in .NET SDK Source code available at http://goo.gl/BftpIi
Dim apiUrl As String = String.Format("email/{0}/properties/{1}?storage={2}&folder={3}", name, propertyName, storage, folder)

ServiceController.Put(apiUrl, appSid, appKey, JsonConvert.SerializeObject([property]))
Wiki Markup
{card}
Wiki Markup
{card:label=Java}
Code Block
 
Wiki Markup
{card}
Wiki Markup
{card:label=PHP}
Code Block
 
Wiki Markup
{card}
Wiki Markup
{card:label=Ruby}
Code Block
 
Wiki Markup
{card}
Wiki Markup
{card:label=Python}
Code Block
 
Wiki Markup
{card}
Wiki Markup
{card:label=Perl}
Code Block
languageperl
 
Wiki Markup
{card}
Wiki Markup
{card:label=Node.js}
Code Block
languagejavascript
 
Wiki Markup
{card}
Wiki Markup
{card:label=C++}
Code Block
languagecpp
 
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/";

boolean isPropertyUpdated = false;
String fileName = "Message.msg";
String propertyName = "Body";
String propertyValue = "New body text";

//build URL
String strURL = EMAIL_URI + Uri.encode(fileName) + "/properties/" + Uri.encode(propertyName);
//sign URL
String signedURL = Utils.sign(strURL);

EmailProperty emailProperty = new EmailProperty();
emailProperty.name = propertyName;
emailProperty.value = propertyValue;

//Encoding to JSON
Gson gson = new Gson();
String jsonStr = gson.toJson(emailProperty);

InputStream responseStream = Utils.processCommand(signedURL, "PUT", jsonStr);
String responseStr = Utils.streamToString(responseStream);

//Parsing JSON
EmailPropertyResponse emailPropertyResponse = gson.fromJson(responseStr, EmailPropertyResponse.class);
if(emailPropertyResponse.getCode().equals("200") && emailPropertyResponse.getStatus().equals("OK")) {
    isPropertyUpdated = true;
}

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/"];

BOOL isPropertyUpdated = NO;
NSString *fileName = @"Self Assessment.eml";
NSString *propertyName = @"Body";
NSString *propertyValue = @"New body text";

//build URL
NSString *strURL = [NSString stringWithFormat:@"%@%@/properties/%@", EMAIL_URI,
                    [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], propertyName];

ASPOSEEmailProperty *emailProperty =  [[ASPOSEEmailProperty alloc] init];
emailProperty.name = propertyName;
emailProperty.value = propertyValue;

NSString *requestJSONString = [emailProperty toJSONString];

//sign URL
NSString *signedURL = [ASPOSEUtils sign:strURL];

NSData *responseData = [ASPOSEUtils processCommand:signedURL httpMethod:@"PUT" content:requestJSONString contentType:CONTENT_TYPE_JSON];

//Parsing JSON
if(responseData) {
    NSError *error;
    ASPOSEEmailPropertyResponse *emailPropertyResponse = [[ASPOSEEmailPropertyResponse alloc] initWithData:responseData error:&error];
    if(!error && [emailPropertyResponse.code isEqualToString:@"200"] && [emailPropertyResponse.status isEqualToString:@"OK"]) {
        isPropertyUpdated = YES;
    }
}

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/properties/Subject?appSID=XXXX&signature=XXXX" \
     -X PUT \
     -d '{"Name": "Subject", "Value": "This is a new subject"}' \
     -H "Content-Type: application/json" \
     -H "Accept: application/json"
Expand
titleResponse
Code Block
{
  "EmailProperty": {
    "Link": {
      "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Subject",
      "Rel": "self",
      "Type": null,
      "Title": null
    },
    "Name": "Subject",
    "Value": "This is a new subject"
  },
  "Code": 200,
  "Status": "OK"
}

SDK Examples

Panel
titleSet message property
Expand
titleC#
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-DotNET-CSharp-Email-Properties-SetMessageProperty-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-properties-SetMessagePropertyExample-SetMessagePropertyExample.java"></script>
Expand
titlePHP
HTML
<script src="https://gist.github.com/a052f420f51722082cbb70d5e8d0f339.js?file=Examples-PHP-Email Properties-PutSetEmailProperty-.php"></script>
Expand
titleRuby
HTML
<script src="https://gist.github.com/aspose-email/3f41448648db89803193189f274722fa.js?file=Examples-Ruby-EmailProperties-set_email_property-.rb
"></script>
Expand
titlePython
HTML
<script src="https://gist.github.com/aspose-email/13478a90f198800bfcdafa983dbd0fcd.js?file=SetMessageProperty.py"></script>
Expand
titleNode.js
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Node.js-Email-Properties-SetMessageProperty-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-properties-SetMessagePropertyExample-SetMessagePropertyExample.java"></script>
Expand
titleObjective C
HTML
<script src="https://gist.github.com/1779f6b192c8df02d5c083a6abedfb62.js?file=Examples-Objective C-Aspose.Email-Aspose.Email-EmailProperties-EmailProperty-PutSetEmailProperty.m"></script>
Expand
titlePerl
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Perl-Email-Properties-SetMessageProperty-1.pl"></script>