Quick Start With Email Client

Built-In Email Client

Aspose.Email Cloud API contains a built-in email client.

The built-in email client supports:

  • SMTP
  • POP3
  • IMAP
  • EWS
  • WebDav
  • Virtual multi-account

Virtual multi-account is a fast and convenient way to set up multiple email accounts and use them as a single one.

How to Work With Email Client

Before we start, we should set up an email account. This allows you to process your messages with built-in Email Client which is developed by Aspose.Email Cloud.

The created email account will be saved on storage, so you don’t have to repeat this operation later.

Create Email Account File

You can create an email account online using Swagger UI or follow the instructions from these guides: Single Email Account Setup and Multi Email Account Setup.

  1. Open link and click “Try it out” button
  2. Enter JSON with email account information and click “Execute” button

{ "Value":{ "Host":"imap.gmail.com", "Port":993, "SecurityOptions":"SSLAuto", "ProtocolType":"IMAP", "Credentials":{ "Password":"password", "Login":"example@gmail.com", "Discriminator":"EmailClientAccountPasswordCredentials" } }, "StorageFile":{ "FileName":"imap.account", "Storage":"First Storage", "FolderPath":"folder/on/storage" } }

Setup email account

First of all, you need to set up your email account’s credentials with EmailClientAccountPasswordCredentials class. Define two fields: Login (Email client account login) and Password (Email client account password).

Then you need to initialize EmailClientAccount object. Let’s define the following parameters:

  • Host — Mail server hostname or IP address.
  • Port — Mail server port.
  • ProtocolType — Type of connection protocol. Enum, available values: IMAP, POP3, SMTP, EWS, WebDav.
  • SecurityOptions — Email account security mode Enum, available values: None, SSLExplicit, SSLImplicit, SSLAuto, Auto.
  • Credentials — Email client account credentials that we have created before.

To save your email account use SaveEmailClientAccountAsync from EmailApi. You should create a request for this operation using SaveEmailClientAccountRequest. To use this request you need to pass into it StorageFileRqOfEmailClientAccount model, which has 2 parameters:

  • Value — Object we want to save on Storage.
  • StorageFile — StorageFileLocation object, which contains IMAP account’s file location information, including storage name, a path to an account folder, name of the file with IMAP account’s configurations.

Search Emails

Search Emails with Swagger UI

Before you start, please try to search emails in your email account’s folders to see how it works. To do this use Swagger UI and follow instructions below:

  1. Open link and click “Try it out” button
  2. Enter email folder, query, account file location:
    1. folder = “INBOX”
    2. firstAccount: “imap.account”
    3. queryString: “(‘From’ Contains ‘.com’)”
    4. secondAccount should be empty
    5. storage: “First storage”
    6. storageFolder: “folder/on/storage”
    7. recursive: true
  3. Click the “Execute” button.

Search Emails Using Aspose.Email Cloud SDKs

To search for emails in your email account’s folders you need to call ListEmailModelsAsync from EmailAPI. This method has one parameter — ListEmailModelsRequest, which is a request model for this operation. In this model you should define the following fields:

  • Folder — A folder in email account.
  • QueryString — A MailQuery search string.
  • FirstAccount — Email account.
  • SecondAccount [optional] — Additional email account (should be specified for POP/IMAP accounts and should be SMTP account).
  • Storage — Storage name where account file(s) located.
  • StorageFolder — Folder in storage where account file(s) located.
  • Recursive [optional] — Specifies that should message be searched in subfolders recursively.

After that, you will get a list of messages matching your search criteria as ListResponseOfEmailDto.

Now you can search emails

Fetch Message By Id

Fetch Message By Id With Swagger UI

Try to fetch email by its Id from your email account’s folders to see how it works. To do this use Swagger UI and follow instructions below:

  • Open link and click “Try it out” button
  • Enter message id and account file location
    • messageId:
    • firstAccount: “imap.account”
    • secondAccount should be empty
    • storage: “First storage”
    • storageFolder: “folder/on/storage”
  • Click the “Execute” button

Fetch Email By Id Using Aspose.Email Cloud SDKs

In the previous step, we have got a list of emails. Let’s fetch one of them by its Id.

To do this you should use the email’s Id, obviously, and FetchEmailModelAsync method from EmailApi. This method requires 1 parameter — FetchEmailModelRequest, which is a request model for this operation.  FetchEmailModelRequest has the following parameters:

  • MessageId — Message identifier. 
  • FirstAccount — Email account.
  • SecondAccount [optional] — Additional email account (should be specified for POP/IMAP accounts and should be SMTP account).
  • Storage — Storage name where account file(s) located.
  • StorageFolder — Folder in storage where account file(s) located.

Аfter this operation you will receive an email as EmailDto.

Fetch found message by id

Mark Message as Read

Using API you are able to mark a message as read by its Id. Try to do this with Swagger UI:

  1. Open link and click “Try it out” button.
  2. Use this JSON example in Swagger UI to do this operation:

{

  "firstAccount": "imap.account",

  "storageFolder": {

    "storage": "First storage",

    "folderPath": "folder/on/storage"

  },

  "messageId": "<message identifier>",

  "isRead": true

}


Mark Message as Read Using Aspose.Email Cloud SDKs

You need to know message’s Id to mark it as read. We have done it in previous steps.

To mark a message as read use SetEmailReadFlagAsync from EmailApi. This method requires 1 parameter — SetEmailReadFlagRequest, which requests a model for this operation.

The request accepts only 1 parameter — SetMessageReadFlagAccountBaseRequest, which is a request to set a message as read.

SetMessageReadFlagAccountBaseRequest has 5 parameters:

  • FirstAccount — First account storage file name for receiving emails (or universal one).
  • SecondAccount [oprional] — Second account storage file name for sending emails (ignored if first is universal).
  • StorageFolder — Storage folder location of account files.
  • MessageId — Message identifier.
  • IsRead — Specifies that message should be marked read or unread.

Mark message as read

Delete Message

Delete Message With Swagger UI

In an attempt to manage your messages, you may need to delete some of them. Try to delete a message with Swagger UI:

  • Open link and click “Try it out” button
  • Enter JSON to specify account, message to delete and click the “Execute” button

Use this JSON example in Swagger UI to do this operation:


{

  "firstAccount": "imap.account",

  "storageFolder": {

    "storage": "First storage",

    "folderPath": "folder/on/storage"

  },

  "messageId": "<message identifier>",

  "deletePermanently": true

}


Delete Message Using Aspose.Email Cloud SDKs

To remove a message, you should know the Id of the email you want to delete.

To delete email use from DeleteEmailMessageAsync from EmailApi. This method requires 1 parameter — DeleteEmailMessageRequest, which requests a model for this operation.

To initialize DeleteEmailMessageRequest you should pass 1 parameter — DeleteMessageBaseRequest, which is a delete message request.

DeleteMessageBaseRequest requires the following parameters:

  • FirstAccount — First account storage file name for receiving emails (or universal one).
  • SecondAccount [oprional] — Second account storage file name for sending emails (ignored if first is universal).
  • StorageFolder — Storage folder location of account files.
  • MessageId — Message identifier.
  • DeletePermanently — Specifies that message should be deleted permanently.

Delete message

Append new message

Append New Message With Swagger UI

Try to append a message to your email account with Swagger UI:

  • Open link and click “Try it out” button
  • Enter JSON with an email message, folder and account information, then click “Execute” button.

Use this JSON example in Swagger UI to do this operation:


{

  "firstAccount": "imap.account",

  "storageFolder": {

    "storage": "First storage",

    "folderPath": "folder/on/storage"

  },

  "folder": "INBOX",

  "markAsSent": true,

  "message":{

    "body":"Some body",

    "from":{

       "displayName":"From address",

       "address":"example@gmail.com"

    },

    "subject":"Some subject",

    "to":[

       {

          "displayName":"To address",

          "address":"to@aspose.com"

       }

    ]

  }

}


Append New Message Using Aspose.Email Cloud SDKs

To append a new message to your email account — use AppendEmailModelMessageAsync from EmailApi. This method requires 1 parameter — AppendEmailModelMessageRequest, which requests a model for this operation.

To initialize AppendEmailModelMessageRequest you should pass 1 parameter — AppendEmailModelRq, which is an append email request.

AppendEmailModelRq requires the following parameters:

  • FirstAccount — First account storage file name for receiving emails (or universal one).
  • SecondAccount [oprional] — Second account storage file name for sending emails (ignored if first is universal).
  • StorageFolder — Storage folder location of account files.
  • MarkAsSent — Mark message as sent.
  • Message — Email document.

Append new message

Setup email account for sending messages

Setup Email Account For Sending Messages With Swagger UI

Try to setup an account to send messages with Swagger UI:

  • Open link and click “Try it out” button
  • Enter JSON with email account information and click “Execute” button

Use this JSON example in Swagger UI to do this operation:


{

   "Value":{

      "Host":"smtp.gmail.com",

      "Port":465,

      "SecurityOptions":"SSLAuto",

      "ProtocolType":"SMTP",

      "Credentials":{

         "Password":"password",

         "Login":"example@gmail.com",

         "Discriminator":"EmailClientAccountPasswordCredentials"

      }

   },

   "StorageFile":{

      "FileName":"smtp.account",

      "Storage":"First Storage",

      "FolderPath":"folder/on/storage"

   }

}


Setup Email Account For Sending Messages Using Aspose.Email Cloud SDKs

All you have to do to setup your email account for sending messages is to use SaveEmailClientAccountAsync from EmailApi. This method requires 1 parameter — SaveEmailClientAccountRequest, which requests a model for this operation.

To initialize SaveEmailClientAccountRequest you should pass 1 parameter — StorageFileRqOfEmailClientAccount.

StorageFileRqOfEmailClientAccount requires the following parameters:

setup account for sending email messages

Send Email

Send Email With Swagger UI

Try to send an email with Swagger UI:

  • Open (link)[https://apireference.aspose.cloud/email/#/EmailClient/SendEmailModel] and click “Try it out” button
  • Enter JSON with an email message and account information, then click “Execute” button

Use this JSON example in Swagger UI to do this operation:


 {

   "Message":{

      "Body":"Some body",

      "From":{

         "DisplayName":"From address",

         "Address":"example@gmail.com"

      },

      "Subject":"Some subject",

      "To":[

         {

            "DisplayName":"To address",

            "Address":"to@aspose.com"

         }

      ]

   },

   "FirstAccount":"smtp.account",

   "StorageFolder":{

      "Storage":"First Storage",

      "FolderPath":"folder/on/storage"

   }

} 


Send Message Using Aspose.Email Cloud SDKs

To append a new message to your email account — use SendEmailModelAsync from EmailApi. This method requires 1 parameter — SendEmailModelRequest, which requests a model for this operation.

To initialize SendEmailModelRequest you should pass 1 parameter — SendEmailModelRq, which is an append email request.

SendEmailModelRq requires the following parameters:

  • FirstAccount — First account storage file name for receiving emails (or universal one).
  • SecondAccount [oprional] — Second account storage file name for sending emails (ignored if first is universal).
  • StorageFolder — Storage folder location of aup an email account for getticcount files.
  • Message — Email document.

And send a message

More Tutorials

See more Aspose Email tutorials: