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 attachment to a message by attachment name 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:attachment

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";
string attachName = "sample.png";
string folder = "Email";
string storage = string.Empty;

// Build URI to perform request
string apiUrl = string.Format(@"email/{0}/attachments/{1}?storage={2}&folder={3}", name, attachName, storage, folder);

ServiceController.Post(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 attachName As String = "sample.png"
Dim folder As String = "Email"
Dim storage As String = String.Empty

' Build URI to perform request
Dim apiUrl As String = String.Format("email/{0}/attachments/{1}?storage={2}&folder={3}", name, attachName, storage, folder)

ServiceController.Post(apiUrl, appSid, appKey)
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/";

AddEmailAttachmentResponse addEmailAttachmentResponse = null;
String fileName = "Leaves.eml";
String attachmentName = "certificate.png"

//build URL
String strURL = EMAIL_URI + Uri.encode(fileName) + "/attachments/" + Uri.encode(attachmentName);
//sign URL
String signedURL = Utils.sign(strURL);
InputStream responseStream = Utils.processCommand(signedURL, "POST");
String jsonStr = Utils.streamToString(responseStream);

//Parsing JSON
Gson gson = new Gson();
addEmailAttachmentResponse = gson.fromJson(jsonStr, AddEmailAttachmentResponse.class);
if(addEmailAttachmentResponse.getCode().equals("200") && addEmailAttachmentResponse.getStatus().equals("OK")) {
    return addEmailAttachmentResponse;
}

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

ASPOSEAddNewDocumentResponse *addEmailAttachmentResponse = nil;
NSString *fileName = @"Monthly Report.eml";
NSString *attachmentName = @"sample.jpg";

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

//sign URL
NSString *signedURL = [ASPOSEUtils sign:strURL];
NSData *responseData = [ASPOSEUtils processCommand:signedURL httpMethod:@"POST"];

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

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/attachments/README.TXT?appSID=XXXX&signature=XXXX" \
     -X POST \
     -H "Content-Type: application/json" \
     -H "Accept: application/json"
Expand
titleResponse
Code Block
{
  "Document": {
    "Links": [
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml",
        "Rel": "self",
        "Type": null,
        "Title": null
      },
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml?format=eml",
        "Rel": "alternate",
        "Type": "application/eml",
        "Title": "Download as EML"
      },
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml?format=msg",
        "Rel": "alternate",
        "Type": "application/msg",
        "Title": "Download as MSG"
      },
      {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml?format=mht",
        "Rel": "alternate",
        "Type": "application/mht",
        "Title": "Download as MHT"
      }
    ],
    "DocumentProperties": {
      "Link": {
        "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/",
        "Rel": "self",
        "Type": null,
        "Title": null
      },
      "List": [
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Bcc",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Bcc",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Body",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Body",
          "Value": "test message"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/CC",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "CC",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Date",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Date",
          "Value": "\/Date(1400060620000)\/"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/DeliveryNotificationOptions",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "DeliveryNotificationOptions",
          "Value": 0
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/From",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "From",
          "Value": "masood@kpisol.com"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/To",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "To",
          "Value": "masood@kpisol.com"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/HtmlBody",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "HtmlBody",
          "Value": ""
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/IsBodyHtml",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "IsBodyHtml",
          "Value": false
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/MessageId",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "MessageId",
          "Value": "<53733ACC.7050206@kpisol.com>"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Priority",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Priority",
          "Value": "Normal"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Subject",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Subject",
          "Value": "test"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/TextBody",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "TextBody",
          "Value": "test message"
        },
        {
          "Link": {
            "Href": "http://api.aspose.cloud/v1.1/email/email_test.eml/documentproperties/Attachments",
            "Rel": "self",
            "Type": null,
            "Title": null
          },
          "Name": "Attachments",
          "Value": [
            {
              "Name": "README.TXT"
            },
            {
              "Name": "README.TXT"
            }
          ]
        }
      ]
    }
  },
  "Code": 200,
  "Status": "OK"
}

SDK Examples

Panel
titleAdd email attachment
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-AddNewAttachment-AddNewAttachment.java"></script>
Expand
titlePHP
HTML
<script src="https://gist.github.com/a052f420f51722082cbb70d5e8d0f339.js?file=Examples-PHP-Attachments-PostAddEmailAttachment-.php"></script>
Expand
titleRuby
HTML
<script src="https://gist.github.com/aspose-email/3f41448648db89803193189f274722fa.js?file=Examples-Ruby-Attachments-add_email_attachment-.rb"></script>
Expand
titlePython
HTML
<script src="https://gist.github.com/aspose-email/13478a90f198800bfcdafa983dbd0fcd.js?file=AddNewAttachment.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-attachments-AddNewAttachment-AddNewAttachment.java"></script>
Expand
titleObjective C
HTML
<script src="https://gist.github.com/1779f6b192c8df02d5c083a6abedfb62.js?file=Examples-Objective C-Aspose.Email-Aspose.Email-Attachments-Attachment-PostAddEmailAttachment.m"></script>
Expand
titlePerl
HTML
<script src="https://gist.github.com/aspose-email/838d7478e3720f941514d3d04417e82e.js?file=Examples-Perl-Email-AddNewEmail-1.pl"></script>