Getting Started with C# and SparkPost
Tags: api, csharp, beginners, sdk
Published: 2017-09-20 18:47:56

---
title: "Getting Started with C# and SparkPost"
published: true
tags: api,csharp,beginners,sdk
canonical_url: https://www.sparkpost.com/blog/csharp-and-sparkpost/
---

### There’s a Better Way to Send Email in C&#35;

Sending email is a very common need for C# applications. Think about some of the use cases almost every app needs to handle: new user welcomes, event notifications, password resets, and so on. These transactional emails are workhorses, and it’s really important that they get to your users. As a C# developer, what’s the best way to get them done?

There are several C# email libraries out there, including system.net.mail, systems.web.mail. SmtpClient, MailKit, MimeKit, etc., but they all have one thing in common: you need an SMTP server to use them. Even if you have access to a server, it’s probably not tuned to ensure your messages get to your user’s inbox quickly and consistently. Using the SparkPost email delivery service is an easier way.

Let’s give it a try. Here’s how to send a message using SparkPost and C#.

### Hello, World! I’m Sending Email with C# and SparkPost

The first step in sending email using C# with SparkPost is to [sign up for a SparkPost developer account](https://pages.sparkpost.com/bl-account-signup-generic.html?src=Blog&pc=bl-rfi-generic-2017&utm_source=blog&utm_medium=blog&utm_campaign=all&utm_content=signup) and get your sending domain configured. Follow our [Getting Started Guide](https://www.sparkpost.com/docs/getting-started/getting-started-sparkpost/) to get your account set up right with a sending domain. I’ll wait right here.

With your account set up, your sending domain configured, and your API key in hand, you’re ready to send your first email using C#. Create an application and install Sparkpost Nuget package from your Nuget [Package Manager Console](http://docs.nuget.org/consume/package-manager-console):

```csharp
PM> Install-Package SparkPost
```

With SparkPost installed, we can format and send our first C# email message:

```csharp
// start by creating a new SparkPost transmission
var transmission = new SparkPost.Transmission();
transmission.Content.From.Email = "me@YOURSENDINGDOMAIN.com";
transmission.Content.Subject = "Hello from SparkPost!";
transmission.Content.Text = "This is a test email.";

// add recipients who will receive your email
var recipient = new Recipient
{
    Address = new Address { Email = "you@YOUREMAILADDRESS.com" }
};
transmission.Recipients.Add(recipient);

// create a new API client using your API key
var client = new Client("<YOUR API KEY HERE>");

// if you do not understand async/await, use the sync sending mode:
client.CustomSettings.SendingMode = SendingModes.Sync;
var response = client.Transmissions.Send(transmission);

// if you understand async/await, use the default async sending mode:
// var response = client.Transmissions.Send(transmission);

// to get the transmission id back from SparkPost
// response.Result.Id;

// to get the status code of the SparkPost response
// response.Result.StatusCode;

// to get the raw json result from SparkPost
// response.Result.Content;
```

And that’s it! Launch the application and you should see a test message in your inbox. And the best part? You don’t have to manage any servers, monitor any services, or worry about whether the message will reach its recipient. You take care of deciding what to send and to whom, and SparkPost takes care of the rest.

### Stay Tuned for More C# Email Tips

You’re well on your way to being a C# email master, thanks to one simple API. You have a working sending domain, you’ve sent your first message, and soon you will conquer the email world!

That said, your journey is not yet complete. Do you really want to have to combine content and design by building your email templates in code? Of course not! Stay tuned and I will show you how to separate the content of the message out of your API call and pre-store the message template, simplifying your code even further.

Till then, [sign up for SparkPost](https://pages.sparkpost.com/bl-account-signup-generic.html?src=Blog&pc=bl-rfi-generic-2017&utm_source=blog&utm_medium=blog&utm_campaign=all&utm_content=signup), [set up your domain](https://www.sparkpost.com/docs/getting-started/getting-started-sparkpost/#preparing-your-from-address), and check out our [great API documentation](https://developer.sparkpost.com/api/)! If you have any other questions around C# and SparkPost, come to the #csharp channel in our [community slack](http://slack.sparkpost.com).

_This post was originally published on [sparkpost.com](https://www.sparkpost.com/blog/csharp-and-sparkpost/)_