To integrate Mailtarget to your applications, websites, or systems with email functionality using C# is easy.
Endpoints
All calls to the API need to start with the appropriate base URL:
Mailtarget production |
Implementation
Here’s the basic code, copy and paste the C# command below into your terminal, you can customize the content according to your needs.
Variable | Descriptions |
API_KEY | API Key in dashboard |
CURLOPT_URL |
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://transmission.mailtarget.co/v1/layang/transmissions");
request.Headers.Add("accept", "application/json");
request.Headers.Add("Authorization", "Bearer API_KEY");
var content = new StringContent('{
"bodyText": "Congratulation, you just sent email with Mailtarget. You are truly awesome!",
"bodyHtml": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>Hello from Mailtarget</title></head><body><p>Congratulation, you just sent email with Mailtarget. You are truly awesome!</p></body></html>",
"from": {
"email": "SENDER_EMAIL",
"name": "SENDER_NAME"
},
"subject": "Hello from Mailtarget",
"to": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"replyTo": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"cc": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"bcc": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"headers": [
{
"name": "",
"value": ""
}
],
"attachments": [
{
"mimeType": "image/png",
"filename": "FILE_NAME.png",
"value": "BASE64_ENCODED_CONTENT"
}
],
"metadata": {
"key1": "value1",
"key2": "value2",
},
"templateId":"TEMPLATE_ID"
}', null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Note :
API_KEY → change with API Key
SENDER_EMAIL → change with sender email
SENDER_NAME → change with sender name
RECIPIENT_EMAIL → change with recipient email
RECIPIENT_NAME → change with recipient name
TEMPLATE_ID → change with template ID