Create, Update, and Delete Contacts in Gmail using C#

Create, Update, and Delete Contacts in Gmail using C#

Gmail is one of the popular and widely used email applications around the globe. Along with managing emails, it allows working with calendars, contacts, chats, etc. and provides other collaboration services. In the previous article, you have seen how to import contacts from a Gmail account within a .NET application. In this article, we will cover how to create, update, and delete contacts in a Gmail account using C# .NET.

C# .NET API to Create, Update and Delete Gmail Contacts

To create and manipulate contacts in a Gmail account, we will use Aspose.Email for .NET. It is an email processing API that lets you manipulate emails and work with popular email clients. You can either download the API’s DLL or install it from NuGet using the following command.

PM> Install-Package Aspose.Email

Before you start working, you need to create a project on the Google Developer Console, which will allow you to communicate with Gmail. To create one, you can follow this guide.

To access and manipulate contacts in a Gmail account, we need to write some code to handle the user’s information and perform authentication. For the Gmail user, we will first create a class named TestUser and then inherit it from GoogleUser class. The following is the complete implementation of both of the classes.

Now, we need to create a helper class that will take care of the authentication of a Gmail account. We will name this class as GoogleOAuthHelper. The following is the complete implementation of this class.

Create a Contact on Gmail in C#

The following are the steps to create a contact on Gmail in C#.

The following code sample shows how to create a contact on Gmail in C#.

Update a Contact on Gmail in C#

You can also update the details of a Gmail contact after accessing it. The following are the steps to update a contact in a Gmail account in C#.

The following code sample shows how to update a contact in Gmail in C#.

Delete a Contact on Gmail in C#

Finally, let’s see how to delete a Gmail contact using C#. The following are the steps to perform this operation.

The following code sample shows how to delete a contact on Gmail in C#.

Get a Free API License

You can use Aspose.Email for .NET without evaluation limitations using a free temporary license.

Conclusion

In this article, you have learned how to create and update contacts in a Gmail account in C# .NET. Furthermore, you have seen how to delete a Gmail contact programmatically. Besides, you can visit the documentation to explore other features of Aspose.Email for .NET. In case you would have any questions, you can post to our forum.

See Also