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 Add new email 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: document.

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>
/// Add new email.
/// </summary>
/// <param name="name">File name. e.g. myEmail.msg</param>
/// <param name="folder">Folder path.</param>
/// <param name="folder">EmailDocument object.</param>
/// <param name="storage">The document storage.</param>
string name; string folder; EmailDocumentPropertiesRequest emailDocumentPropertiesRequest; 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}?storage={1}&folder={2}", name, storage, folder);

ServiceController.Put(apiUrl, appSid, appKey, JsonConvert.SerializeObject(emailDocumentPropertiesRequest));
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>
''' Add new email.
''' </summary>
''' <param name="name">File name. e.g. myEmail.msg</param>
''' <param name="folder">Folder path.</param>
''' <param name="folder">EmailDocument object.</param>
''' <param name="storage">The document storage.</param>
Dim name As String
Dim folder As String
Dim emailDocumentPropertiesRequest As EmailDocumentPropertiesRequest
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}?storage={1}&folder={2}", name, storage, folder)

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

AddNewEmailResponse addNewEmailResponse = null;
String emailName = "newEmail.eml";
EmailDocument emailDocument = new EmailDocument();
emailDocument.links = new ArrayList<LinkModel>();
LinkModel mLink = new LinkModel();
mLink.href = "http://api.aspose.com/v1.1/email/newEmail.eml";
mLink.rel = "self";
mLink.type = null;
mLink.title = null;

emailDocument.links.add(mLink);

emailDocument.emailDocumentProperties = new EmailDocumentProperties();
emailDocument.emailDocumentProperties.link = new LinkModel();
emailDocument.emailDocumentProperties.link.href = "http://api.aspose.com/v1.1/email/newEmail.eml/documentproperties/";
emailDocument.emailDocumentProperties.link.rel = "self";
emailDocument.emailDocumentProperties.link.type = null;
emailDocument.emailDocumentProperties.link.title = null;

emailDocument.emailDocumentProperties.emailPropertiesList = new ArrayList<EmailProperty>();
EmailProperty mEmailProperty = new EmailProperty();
mEmailProperty.name = "From";
mEmailProperty.value = "ben@aspose.com";
emailDocument.emailDocumentProperties.emailPropertiesList.add(mEmailProperty);
mEmailProperty = new EmailProperty();
mEmailProperty.name = "To";
mEmailProperty.value = "marketplace@aspose.com";
emailDocument.emailDocumentProperties.emailPropertiesList.add(mEmailProperty);
mEmailProperty = new EmailProperty();
mEmailProperty.name = "Subject";
mEmailProperty.value = "Leaves Notification";
emailDocument.emailDocumentProperties.emailPropertiesList.add(mEmailProperty);

//build URL
String strURL = EMAIL_URI + Uri.encode(emailName);
//sign URL
String signedURL = Utils.sign(strURL);

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

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

//Parsing JSON
addNewEmailResponse = gson.fromJson(responseStr, AddNewEmailResponse.class);
if(addNewEmailResponse.getCode().equals("200") && addNewEmailResponse.getStatus().equals("OK")) {
    return addNewEmailResponse;
}

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 = @"Marketplace.eml";
ASPOSEEmailCommonInfo *emailData = [[ASPOSEEmailCommonInfo alloc] init];

NSMutableArray<ASPOSEHrefToDocument> *mLinks = (NSMutableArray<ASPOSEHrefToDocument> *) [[NSMutableArray alloc] init];
ASPOSEHrefToDocument *mLink = [[ASPOSEHrefToDocument alloc] init];
mLink.href = @"http://api.aspose.com/v1.1/email/newEmail.eml";
mLink.rel = @"self";
mLink.type = nil;
mLink.title = nil;
[mLinks addObject:mLink];
emailData.links = mLinks;

ASPOSEEDocumentProperties *mDocumentProperties = [[ASPOSEEDocumentProperties alloc] init];
mLink = [[ASPOSEHrefToDocument alloc] init];
mLink.href = @"http://api.aspose.com/v1.1/email/newEmail.eml/documentproperties/";
mLink.rel = @"self";
mLink.type = nil;
mLink.title = nil;
mDocumentProperties.link = mLink;

NSMutableArray<ASPOSEEmailProperty> *emailPropertiesList = (NSMutableArray<ASPOSEEmailProperty> *) [[NSMutableArray alloc] init];

ASPOSEEmailProperty *emailProperty = [[ASPOSEEmailProperty alloc] init];
emailProperty.name = @"From";
emailProperty.value = @"ben@aspose.com";
[emailPropertiesList addObject:emailProperty];

emailProperty = [[ASPOSEEmailProperty alloc] init];
emailProperty.name = @"To";
emailProperty.value = @"marketplace@aspose.com";
[emailPropertiesList addObject:emailProperty];

emailProperty = [[ASPOSEEmailProperty alloc] init];
emailProperty.name = @"Subject";
emailProperty.value = @"Progress Report";
[emailPropertiesList addObject:emailProperty];

mDocumentProperties.list = emailPropertiesList;

emailData.documentProperties = mDocumentProperties;

NSString *requestJSONString = [emailData toJSONString];

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

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

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

if(responseData) {
    NSError *error;
    ASPOSEAddNewDocumentResponse *addNewEmailResponse = [[ASPOSEAddNewDocumentResponse alloc] initWithData:responseData error:&error];
    if(!error && [addNewEmailResponse.code isEqualToString:@"200"] && [addNewEmailResponse.status isEqualToString:@"OK"]) {
        return addNewEmailResponse;
    }
}

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_test2.eml?appSID=XXXX&signature=XXXX" \
     -X PUT \
    -d '{"DocumentProperties": {"List": [{"Name": "Body", "Value": "This is body"}, {"Name": "To", "Value": "developer@aspose.com"}, {"Name": "From", "Value": "sales@aspose.com"}]}, "Format": "eml"}' \
     -H "Content-Type: application/json" \
     -H "Accept: application/json"
Expand
titleResponse
Code Block
{
  "Document": {
    "Links": [
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml",
        "Rel": "self",
        "Type": null,
        "Title": null
      },
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml?format=eml",
        "Rel": "alternate",
        "Type": "application/eml",
        "Title": "Download as EML"
      },
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml?format=msg",
        "Rel": "alternate",
        "Type": "application/msg",
        "Title": "Download as MSG"
      },
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml?format=mht",
        "Rel": "alternate",
        "Type": "application/mht",
        "Title": "Download as MHT"
      }
    ],
    "DocumentProperties": {
      "Link": {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/",
        "Rel": "self",
        "Type": null,
        "Title": null
      },
      "List": [
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/Bcc",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Bcc",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/Body",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Body",
          "Value": "This is body"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/CC",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "CC",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/Date",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Date",
          "Value": "\/Date(1491769809496+0000)\/"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/DeliveryNotificationOptions",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "DeliveryNotificationOptions",
          "Value": 0
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/From",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "From",
          "Value": "sales@aspose.com"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/To",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "To",
          "Value": "developer@aspose.com"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/HtmlBody",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "HtmlBody",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/IsBodyHtml",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "IsBodyHtml",
          "Value": false
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/MessageId",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "MessageId",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/Priority",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Priority",
          "Value": "Normal"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/Subject",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Subject",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/TextBody",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "TextBody",
          "Value": "This is body"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test2.eml/documentproperties/Attachments",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Attachments",
          "Value": [
            
          ]
        }
      ]
    }
  },
  "Code": 200,
  "Status": "OK"
}

SDK Examples

Panel
titleAdd new email
Expand
titleC#
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-DotNET-CSharp-Email-AddNewEmail-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-AddNewEmailExample-AddNewEmailExample.java"></script> 
Expand
titlePHP
HTML
<script src="https://gist.github.com/a052f420f51722082cbb70d5e8d0f339.js?file=Examples-PHP-Email-PutCreateNewEmail-.php"></script>
Expand
titleRuby
HTML
<script src="https://gist.github.com/aspose-email/3f41448648db89803193189f274722fa.js?file=Examples-Ruby-Email-add_new_email-.rb"></script>
Expand
titlePython
HTML
<script src="https://gist.github.com/aspose-email/13478a90f198800bfcdafa983dbd0fcd.js?file=AddNewEmail.py"></script>
Expand
titleNode.js
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Node.js-Email-AddNewEmail-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-AddNewEmailExample-AddNewEmailExample.java"></script>
Expand
titleObjective C
HTML
<script src="https://gist.github.com/1779f6b192c8df02d5c083a6abedfb62.js?file=Examples-Objective C-Aspose.Email-Aspose.Email-Email-Email-PutCreateNewEmail.m"></script>
Expand
titlePerl
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Perl-Email-AddNewEmail-1.pl"></script>