Skip to content

Commit b6da27a

Browse files
committed
Merge branch 'main' of github.com:socketlabs/socketlabs-csharp
2 parents 358a0eb + 2d88628 commit b6da27a

30 files changed

+740
-134
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ do so.
1414

1515
* Check that the issue has not already been reported.
1616
* Check that the issue has not already been fixed in the latest code
17-
(a.k.a. `master`).
17+
(a.k.a. `main`).
1818
* Be clear, concise and precise in your description of the problem.
1919
* Open an issue with a descriptive title and a summary in grammatically correct,
2020
complete sentences.
@@ -27,7 +27,7 @@ You can request a new feature by submitting an issue to our
2727
consider what kind of change it is:
2828

2929
* **Major Changes** that you wish to contribute to the project should be
30-
discussed first with `csharp-socketlabs` contributors in an issue or pull request so
30+
discussed first with `socketlabs-csharp` contributors in an issue or pull request so
3131
that we can develop a proper solution and better coordinate our efforts,
3232
prevent duplication of work, and help you to craft the change so that it is
3333
successfully accepted into the project.
@@ -38,7 +38,7 @@ consider what kind of change it is:
3838

3939
- Create a personal fork of the project on Github.
4040
- If you created your fork a while ago be sure to pull upstream changes into your local repository.
41-
- Create a new branch to work on! Branch from `master`.
41+
- Create a new branch to work on! Branch from `main`.
4242
- Implement/fix your feature, comment your code.
4343
- Write or adapt tests as needed.
4444
- Add or change the documentation as needed.

Example Projects/dotNetCoreExample/Examples/Basic/BasicComplexExample.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,36 @@ public SendResponse RunExample()
1010
{
1111
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey);
1212

13+
// Build the message
1314
var message = new BasicMessage();
1415

15-
message.To.Add("[email protected]");
16-
message.To.Add("[email protected]", "Recipient #2");
17-
1816
message.Subject = "Sending Basic Complex Example";
1917
message.HtmlBody = "<body><p><strong>Lorem Ipsum</strong></p><br /><img src=\"cid:Bus\" /></body>";
2018
message.PlainTextBody = "Lorem Ipsum";
19+
message.AmpBody = "<!doctype html>" +
20+
"<html amp4email>" +
21+
"<head>" +
22+
" <meta charset=\"utf-8\">" +
23+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
24+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
25+
" <style amp-custom>" +
26+
" h1 {" +
27+
" margin: 1rem;" +
28+
" }" +
29+
" </style>" +
30+
"</head>" +
31+
"<body>" +
32+
" <h1>This is the AMP Html Body of my message</h1>" +
33+
"</body>" +
34+
"</html>";
35+
2136
message.CharSet = "utf-8";
2237

38+
// Add recipients
39+
message.To.Add("[email protected]");
40+
message.To.Add("[email protected]", "Recipient #2");
41+
42+
// Set other properties as needed
2343
message.From.Email = "[email protected]";
2444
message.ReplyTo.Email = "[email protected]";
2545

@@ -31,6 +51,7 @@ public SendResponse RunExample()
3151
var attachment = message.Attachments.Add("bus.png", MimeType.PNG, @".\examples\img\bus.png");
3252
attachment.ContentId = "Bus";
3353

54+
// Send the message
3455
return client.Send(message);
3556
}
3657
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using SocketLabs.InjectionApi;
2+
using SocketLabs.InjectionApi.Message;
3+
4+
namespace dotNetCoreExample.Examples.Basic
5+
{
6+
public class BasicSendWithAmpBody : IExample
7+
{
8+
public SendResponse RunExample()
9+
{
10+
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
11+
{
12+
EndpointUrl = ExampleConfig.TargetApi
13+
};
14+
15+
// Build the message
16+
var message = new BasicMessage();
17+
18+
message.Subject = "Sending A Test Message";
19+
message.HtmlBody = "<html>This Html text will show if Amp is not supported/not implemented properly.</html>";
20+
message.AmpBody = "<!doctype html>" +
21+
"<html amp4email>" +
22+
"<head>" +
23+
" <meta charset=\"utf-8\">" +
24+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
25+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
26+
" <style amp-custom>" +
27+
" h1 {" +
28+
" margin: 1rem;" +
29+
" }" +
30+
" </style>" +
31+
"</head>" +
32+
"<body>" +
33+
" <h1>This is the AMP Html Body of my message</h1>" +
34+
"</body>" +
35+
"</html>";
36+
37+
38+
39+
40+
// Add recipients
41+
message.To.Add("[email protected]");
42+
message.To.Add("[email protected]", "Recipient #2");
43+
message.To.Add(new EmailAddress("[email protected]"));
44+
message.To.Add(new EmailAddress("[email protected]", "Recipient #4"));
45+
46+
// Set other properties as needed
47+
message.From.Email = "[email protected]";
48+
message.ReplyTo.Email = "[email protected]";
49+
50+
//Send message
51+
return client.Send(message);
52+
}
53+
}
54+
}

Example Projects/dotNetCoreExample/Examples/Basic/BasicSendWithAttachment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public SendResponse RunExample()
2222
message.ReplyTo.Email = "[email protected]";
2323
message.To.Add("[email protected]");
2424

25-
var attachment = message.Attachments.AddAsync("bus.png", MimeType.PNG, @".\examples\img\bus.png").Result;
25+
var attachment = message.Attachments.Add("bus.png", MimeType.PNG, @".\examples\img\bus.png");
2626

2727
attachment.CustomHeaders.Add(new CustomHeader("Color", "Orange"));
2828
attachment.CustomHeaders.Add(new CustomHeader("Place", "Beach"));

Example Projects/dotNetCoreExample/Examples/Basic/BasicSendWithProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class BasicSendWithProxy : IExample
88
{
99
public SendResponse RunExample()
1010
{
11-
var proxy = new WebProxy("http://localhost.:8888", false);
11+
var proxy = new WebProxy("http://localhost:4433", false);
1212

1313
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey, proxy)
1414
{
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Net;
3+
using SocketLabs.InjectionApi;
4+
using SocketLabs.InjectionApi.Message;
5+
6+
namespace dotNetCoreExample.Examples.Basic
7+
{
8+
public class BasicSendWithRetry : IExample
9+
{
10+
public SendResponse RunExample()
11+
{
12+
var proxy = new WebProxy("http://localhost:4433", false);
13+
14+
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey, proxy)
15+
{
16+
EndpointUrl = ExampleConfig.TargetApi,
17+
NumberOfRetries = 3
18+
};
19+
20+
var message = new BasicMessage();
21+
22+
message.Subject = "Sending A Test Message With Retry Enabled";
23+
message.HtmlBody = "<html>This is the Html Body of my message.</html>";
24+
message.PlainTextBody = "This is the Plain Text Body of my message.";
25+
26+
message.From.Email = "[email protected]";
27+
message.ReplyTo.Email = "[email protected]";
28+
message.To.Add("[email protected]");
29+
30+
return client.Send(message);
31+
}
32+
}
33+
}

Example Projects/dotNetCoreExample/Examples/Bulk/BulkSendComplexExample.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,39 @@ public SendResponse RunExample()
6767
html.AppendLine("</html>");
6868
message.HtmlBody = html.ToString();
6969

70+
// Amp Body option
71+
var amp = new StringBuilder();
72+
amp.AppendLine("<!doctype html>");
73+
amp.AppendLine("<html amp4email>");
74+
amp.AppendLine(" <head><title>Complex AMP Email</title><meta charset=\"utf-8\">");
75+
amp.AppendLine(" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>");
76+
amp.AppendLine(" <style amp4email-boilerplate>body{visibility:hidden}</style>");
77+
amp.AppendLine(" <style amp-custom>");
78+
amp.AppendLine(" h1 {");
79+
amp.AppendLine(" margin: 1rem;");
80+
amp.AppendLine(" }");
81+
amp.AppendLine(" </style></head>");
82+
amp.AppendLine(" <body>");
83+
amp.AppendLine(" <h1>AMP Is Enabled</h1>");
84+
amp.AppendLine(" <h1>Merged Data</h1>");
85+
amp.AppendLine(" <p>");
86+
amp.AppendLine(" Motto = <b>%%Motto%%</b> </br>");
87+
amp.AppendLine(" Birthday = <b>%%Birthday%%</b> </br>");
88+
amp.AppendLine(" Age = <b>%%Age%%</b> </br>");
89+
amp.AppendLine(" UpSell = <b>%%UpSell%%</b> </br>");
90+
amp.AppendLine(" </p>");
91+
amp.AppendLine(" </br>");
92+
amp.AppendLine(" <h1>Example of Merge Usage</h1>");
93+
amp.AppendLine(" <p>");
94+
amp.AppendLine(" Our company motto is '<b>%%Motto%%</b>'. </br>");
95+
amp.AppendLine(" Your birthday is <b>%%Birthday%%</b> and you are <b>%%Age%%</b> years old. </br>");
96+
amp.AppendLine(" </br>");
97+
amp.AppendLine(" <b>%%UpSell%%<b>");
98+
amp.AppendLine(" </p>");
99+
amp.AppendLine(" </body>");
100+
amp.AppendLine("</html>");
101+
message.AmpBody = amp.ToString();
102+
70103
message.PlainTextBody = Regex.Replace(message.HtmlBody, "<.*?>", string.Empty);
71104

72105
// Add an Attachment with a custom header
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using SocketLabs.InjectionApi;
2+
using SocketLabs.InjectionApi.Message;
3+
4+
namespace dotNetCoreExample.Examples.Bulk
5+
{
6+
public class BulkSendWithAmpBody : IExample
7+
{
8+
public SendResponse RunExample()
9+
{
10+
var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
11+
{
12+
EndpointUrl = ExampleConfig.TargetApi
13+
};
14+
15+
// Build the message
16+
var message = new BulkMessage();
17+
18+
message.Subject = "Sending A Test Message";
19+
// HtmlBody will be shown if Amp is not supported/not implemented properly
20+
message.HtmlBody = "<html>This Html Body of my message.</html>";
21+
message.AmpBody = "<!doctype html>" +
22+
"<html amp4email>" +
23+
"<head>" +
24+
" <meta charset=\"utf-8\">" +
25+
" <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
26+
" <style amp4email-boilerplate>body{visibility:hidden}</style>" +
27+
" <style amp-custom>" +
28+
" h1 {" +
29+
" margin: 1rem;" +
30+
" }" +
31+
" </style>" +
32+
"</head>" +
33+
"<body>" +
34+
" <h1>This is the AMP Html Body of my message</h1>" +
35+
"</body>" +
36+
"</html>";
37+
38+
// Add recipients
39+
message.To.Add("[email protected]");
40+
message.To.Add("[email protected]", "Recipient #2");
41+
message.To.Add(new BulkRecipient("[email protected]"));
42+
message.To.Add(new BulkRecipient("[email protected]", "Recipient #4"));
43+
44+
// Set other properties as needed
45+
message.From.Email = "[email protected]";
46+
message.ReplyTo.Email = "[email protected]";
47+
48+
// Send message
49+
return client.Send(message);
50+
}
51+
}
52+
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
namespace dotNetCoreExample.Examples
1+
using System;
2+
namespace dotNetCoreExample.Examples
23
{
34
public static class ExampleConfig
45
{
5-
//public static int ServerId => Environment.GetEnvironmentVariable("SocketlabsServerId", EnvironmentVariableTarget.User);
6-
//public static string ApiKey => Environment.GetEnvironmentVariable("SocketlabsApiPassword", EnvironmentVariableTarget.User);
6+
public static int ServerId => int.Parse(Environment.GetEnvironmentVariable("SocketlabsServerId", EnvironmentVariableTarget.User));
7+
public static string ApiKey => Environment.GetEnvironmentVariable("SocketlabsApiPassword", EnvironmentVariableTarget.User);
78
public static string TargetApi = "https://inject.socketlabs.com/api/v1/email";
8-
9-
public static int ServerId => 0; //your serverId
10-
public static string ApiKey => "your api key";
11-
9+
1210
}
13-
}
11+
}

Example Projects/dotNetCoreExample/Program.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void Main()
2626
quit = selection.ToLower().Trim() == "quit";
2727
if (quit)
2828
continue;
29-
29+
3030
var exampleClassName = GetExampleName(selection);
3131
if(exampleClassName == null)
3232
continue;
@@ -53,19 +53,24 @@ private static void DisplayTheMenu()
5353
Console.WriteLine(" 6: Basic Send With Custom-Headers ");
5454
Console.WriteLine(" 7: Basic Send With Embedded Image ");
5555
Console.WriteLine(" 8: Basic Send With Proxy ");
56-
Console.WriteLine(" 9: Basic Send Complex Example ");
56+
Console.WriteLine(" 9: Basic Send With Retry ");
57+
Console.WriteLine(" 10: Basic Send Complex Example ");
5758
Console.WriteLine();
5859
Console.WriteLine(" Validation Error Handling Examples: ");
59-
Console.WriteLine(" 10: Basic Send With Invalid Attachment");
60-
Console.WriteLine(" 11: Basic Send With Invalid From ");
61-
Console.WriteLine(" 12: Basic Send With Invalid Recipients ");
60+
Console.WriteLine(" 11: Basic Send With Invalid Attachment");
61+
Console.WriteLine(" 12: Basic Send With Invalid From ");
62+
Console.WriteLine(" 13: Basic Send With Invalid Recipients ");
6263
Console.WriteLine();
6364
Console.WriteLine(" Bulk Send Examples: ");
64-
Console.WriteLine(" 13: Bulk Send ");
65-
Console.WriteLine(" 14: Bulk Send With MergeData ");
66-
Console.WriteLine(" 15: Bulk Send With Ascii Charset And MergeData ");
67-
Console.WriteLine(" 16: Bulk Send From DataSource With MergeData ");
68-
Console.WriteLine(" 17: Bulk Send Complex Example (Everything including the Kitchen Sink) ");
65+
Console.WriteLine(" 14: Bulk Send ");
66+
Console.WriteLine(" 15: Bulk Send With MergeData ");
67+
Console.WriteLine(" 16: Bulk Send With Ascii Charset And MergeData ");
68+
Console.WriteLine(" 17: Bulk Send From DataSource With MergeData ");
69+
Console.WriteLine(" 18: Bulk Send Complex Example (Everything including the Kitchen Sink) ");
70+
Console.WriteLine();
71+
Console.WriteLine(" Amp Examples: ");
72+
Console.WriteLine(" 19: Basic Send With Amp Body ");
73+
Console.WriteLine(" 20: Bulk Send With Amp Body ");
6974
Console.WriteLine();
7075
Console.WriteLine("-------------------------------------------------------------------------");
7176
}
@@ -87,16 +92,23 @@ private static string GetExampleName(string selection)
8792
case 5: return "dotNetCoreExample.Examples.Basic.BasicSendWithAttachment";
8893
case 6: return "dotNetCoreExample.Examples.Basic.BasicSendWithCustomHeaders";
8994
case 7: return "dotNetCoreExample.Examples.Basic.BasicSendWithEmbeddedImage";
90-
case 8: return "dotNetCoreExample.Examples.Basic.BasicSendWithProxy";
91-
case 9: return "dotNetCoreExample.Examples.Basic.BasicComplexExample";
92-
case 10: return "dotNetCoreExample.Examples.Basic.Invalid.BasicSendWithInvalidAttachment";
93-
case 11: return "dotNetCoreExample.Examples.Basic.Invalid.BasicSendWithInvalidFrom";
94-
case 12: return "dotNetCoreExample.Examples.Basic.Invalid.BasicSendWithInvalidRecipients";
95-
case 13: return "dotNetCoreExample.Examples.Bulk.BulkSend";
96-
case 14: return "dotNetCoreExample.Examples.Bulk.BulkSendWithMergeData";
97-
case 15: return "dotNetCoreExample.Examples.Bulk.BulkSendWithAsciiCharsetMergeData";
98-
case 16: return "dotNetCoreExample.Examples.Bulk.BulkSendFromDataSourceWithMerge";
99-
case 17: return "dotNetCoreExample.Examples.Bulk.BulkSendComplexExample";
95+
case 8: return "dotNetCoreExample.Examples.Basic.BasicSendWithRetry";
96+
case 9: return "dotNetCoreExample.Examples.Basic.BasicSendWithProxy";
97+
case 10: return "dotNetCoreExample.Examples.Basic.BasicComplexExample";
98+
99+
case 11: return "dotNetCoreExample.Examples.Basic.Invalid.BasicSendWithInvalidAttachment";
100+
case 12: return "dotNetCoreExample.Examples.Basic.Invalid.BasicSendWithInvalidFrom";
101+
case 13: return "dotNetCoreExample.Examples.Basic.Invalid.BasicSendWithInvalidRecipients";
102+
103+
case 14: return "dotNetCoreExample.Examples.Bulk.BulkSend";
104+
case 15: return "dotNetCoreExample.Examples.Bulk.BulkSendWithMergeData";
105+
case 16: return "dotNetCoreExample.Examples.Bulk.BulkSendWithAsciiCharsetMergeData";
106+
case 17: return "dotNetCoreExample.Examples.Bulk.BulkSendFromDataSourceWithMerge";
107+
case 18: return "dotNetCoreExample.Examples.Bulk.BulkSendComplexExample";
108+
109+
case 19: return "dotNetCoreExample.Examples.Basic.BasicSendWithAmpBody";
110+
case 20: return "dotNetCoreExample.Examples.Bulk.BulkSendWithAmpBody";
111+
100112
default:
101113
Console.WriteLine("Invalid Input (Out of Range)");
102114
return null;

0 commit comments

Comments
 (0)