https://github.com/cmdotcom/email-sdk-dotnet
.NET Standard SDK to send email with CM.com
https://github.com/cmdotcom/email-sdk-dotnet
cm dotnet email netstandard nuget sdk
Last synced: 3 months ago
JSON representation
.NET Standard SDK to send email with CM.com
- Host: GitHub
- URL: https://github.com/cmdotcom/email-sdk-dotnet
- Owner: cmdotcom
- License: mit
- Created: 2019-11-14T09:47:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-12T06:14:10.000Z (almost 2 years ago)
- Last Synced: 2025-01-08T12:54:54.687Z (5 months ago)
- Topics: cm, dotnet, email, netstandard, nuget, sdk
- Language: C#
- Size: 66.4 KB
- Stars: 1
- Watchers: 10
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# EmailCampaignsAPI SDK
.NET Standard SDK to send email with the CM EmailCampaigns API## API Documentation
https://docs.cmtelecom.com/en/api/email-campaigns# Usage
## Instantiate a client
```cs
HttpClient httpClient = new HttpClient();
EmailClient emailClient = new EmailClient(httpClient, myApiKey, baseUrl);
````httpClient` is requested as a parameter, such that you can use a single instance throughout your application, as is highly recommended.
`myApiKey` is your unique api key (or product token) which authorizes you on the CM platform. Always keep this key secret!
`baseUrl` is optional and will be defaulted to https://api.cmtelecom.com when not filled in. Else the requests will be send to the filled in domain.
## Send an email
You can send a mail by calling the `SendMailAsync` method and providing your accountID (found in the API credentials under settings in the Email Campaigns app), the Mail object and a cancellation token (optional).
```cs
Mail mail = new Mail()
{
FromAddressID = fromAddressID,
FromName = fromName, //optional
ReplyToAddressID = replyToAddressID, // optional
ReplyToAddress = replyToAddress, // optional (Overwritten when ReplyToAddressID defined)
ReplyToName = replyToName, // optional (Requires ReplyToAddressID or ReplyToAddress to be filled)
ToAddress = toAddress,
ToName = toName, // optional
Ccs = new MailAddress[] // optional
{
new MailAddress() { EmailAddress = ccToAddress }
},
Bccs = new MailAddress[] // optional
{
new MailAddress() { EmailAddress = bccToAddress }
},
Subject = "SDK SingleMail test",
HtmlBody = "What a beautifull email",
TextBody = "What a beautifull email",
Attachments = new Attachment[]
{
new Attachment
{
FileName = attachmentFileName,
Content = attachmentContent, // base64 encoded content of the attachment
ContentID = attachmentContentID // The ContentID can be specified for images, to reference it in your image tag in your HTML. You can use "cid:yourcontentid" in the src tag of the image to display the image inline.
}
}, // optional
CustomerReference = yourOwnReference //optional
};
Mail sendMail = await emailClient.SendMailAsync(accountID, mail).ConfigureAwait(false);
```## Send a triggered campaign mail
You can send a triggered mail by calling the `SendCampaignMailAsync` method and providing your accountID (found in the API credentials under settings in the Email Campaigns app), the triggeredCampaignID over which you want to send the mail, the CampaignMail object (with a ToAddress and custom values) and a cancellation token (optional).
```cs
CampaignMail campaignMail = new CampaignMail()
{
ToAddress = recipientsEmailAddress,
ToName = toName, //optional
CustomValues = new CustomValue[]
{
new CustomValue() { Field = "Firstname", Value = "recipientsFirstname" }
}
};CampaignMail sendCampaignMail = await emailClient.SendCampaignMailAsync(accountID, triggeredCampaignID, campaignMail).ConfigureAwait(false);
```## Other requests
The send mail requests are explained in a bit more detail above because those are the most used methods, but no worries, all other implemented requests are working in a similar way and should be easy to use.