-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElasticEmailClient.cs
7228 lines (6308 loc) · 323 KB
/
ElasticEmailClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
The MIT License (MIT)
Copyright (c) 2016-2017 Elastic Email, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mime;
using System.Text;
using System.Collections.Specialized;
namespace ElasticEmailClient
{
#region Utilities
internal class ApiResponse<T>
{
public bool success = false;
public string error = null;
public T Data
{
get;
set;
}
}
internal class VoidApiResponse
{
}
internal static class ApiUtilities
{
public static byte[] HttpPostFile(string url, List<ApiTypes.FileData> fileData, NameValueCollection parameters)
{
try
{
string boundary = DateTime.Now.Ticks.ToString("x");
byte[] boundarybytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.ContentType = "multipart/form-data; boundary=" + boundary;
wr.Method = "POST";
wr.KeepAlive = true;
wr.Credentials = CredentialCache.DefaultCredentials;
wr.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
wr.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
Stream rs = wr.GetRequestStream();
string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";
foreach (string key in parameters.Keys)
{
rs.Write(boundarybytes, 0, boundarybytes.Length);
string formitem = string.Format(formdataTemplate, key, parameters[key]);
byte[] formitembytes = Encoding.UTF8.GetBytes(formitem);
rs.Write(formitembytes, 0, formitembytes.Length);
}
if(fileData != null)
{
foreach (var file in fileData)
{
rs.Write(boundarybytes, 0, boundarybytes.Length);
string headerTemplate = "Content-Disposition: form-data; name=\"filefoobarname\"; filename=\"{0}\"\r\nContent-Type: {1}\r\n\r\n";
string header = string.Format(headerTemplate, file.FileName, file.ContentType);
byte[] headerbytes = Encoding.UTF8.GetBytes(header);
rs.Write(headerbytes, 0, headerbytes.Length);
rs.Write(file.Content, 0, file.Content.Length);
}
}
byte[] trailer = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
rs.Write(trailer, 0, trailer.Length);
rs.Close();
using (WebResponse wresp = wr.GetResponse())
{
MemoryStream response = new MemoryStream();
wresp.GetResponseStream().CopyTo(response);
return response.ToArray();
}
}
catch (WebException webError)
{
// Throw exception with actual error message from response
throw new WebException(((HttpWebResponse)webError.Response).StatusDescription, webError, webError.Status, webError.Response);
}
}
public static byte[] HttpPutFile(string url, ApiTypes.FileData fileData, NameValueCollection parameters)
{
try
{
string queryString = BuildQueryString(parameters);
if (queryString.Length > 0) url += "?" + queryString.ToString();
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.ContentType = fileData.ContentType ?? "application/octet-stream";
wr.Method = "PUT";
wr.KeepAlive = true;
wr.Credentials = CredentialCache.DefaultCredentials;
wr.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
wr.Headers.Add("Content-Disposition: attachment; filename=\"" + fileData.FileName + "\"; size=" + fileData.Content.Length);
wr.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
Stream rs = wr.GetRequestStream();
rs.Write(fileData.Content, 0, fileData.Content.Length);
using (WebResponse wresp = wr.GetResponse())
{
MemoryStream response = new MemoryStream();
wresp.GetResponseStream().CopyTo(response);
return response.ToArray();
}
}
catch (WebException webError)
{
// Throw exception with actual error message from response
throw new WebException(((HttpWebResponse)webError.Response).StatusDescription, webError, webError.Status, webError.Response);
}
}
public static ApiTypes.FileData HttpGetFile(string url, NameValueCollection parameters)
{
try
{
string queryString = BuildQueryString(parameters);
if (queryString.Length > 0) url += "?" + queryString.ToString();
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.Method = "GET";
wr.KeepAlive = true;
wr.Credentials = CredentialCache.DefaultCredentials;
wr.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
wr.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
using (WebResponse wresp = wr.GetResponse())
{
MemoryStream response = new MemoryStream();
wresp.GetResponseStream().CopyTo(response);
if (response.Length == 0) throw new FileNotFoundException();
string cds = wresp.Headers["Content-Disposition"];
if (cds == null)
{
// This is a special case for critical exceptions
ApiResponse<string> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<string>>(Encoding.UTF8.GetString(response.ToArray()));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return null;
}
else
{
ContentDisposition cd = new ContentDisposition(cds);
ApiTypes.FileData fileData = new ApiTypes.FileData();
fileData.Content = response.ToArray();
fileData.ContentType = wresp.ContentType;
fileData.FileName = cd.FileName;
return fileData;
}
}
}
catch (WebException webError)
{
// Throw exception with actual error message from response
throw new WebException(((HttpWebResponse)webError.Response).StatusDescription, webError, webError.Status, webError.Response);
}
}
static string BuildQueryString(NameValueCollection parameters)
{
if (parameters == null || parameters.Count == 0)
return null;
StringBuilder query = new StringBuilder();
string amp = string.Empty;
foreach (string key in parameters.AllKeys)
{
foreach (string value in parameters.GetValues(key))
{
query.Append(amp);
query.Append(WebUtility.UrlEncode(key));
query.Append("=");
query.Append(WebUtility.UrlEncode(value));
amp = "&";
}
}
return query.ToString();
}
}
internal class CustomWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
return request;
}
}
#endregion
// API version 2.8.2
static class Api
{
public static string ApiKey = "00000000-0000-0000-0000-000000000000";
private static readonly string ApiUri = "https://api.elasticemail.com/v2";
#region Account functions
/// <summary>
/// Methods for managing your account and subaccounts.
/// </summary>
public static class Account
{
/// <summary>
/// Create new subaccount and provide most important data about it.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="email">Proper email address.</param>
/// <param name="password">Current password.</param>
/// <param name="confirmPassword">Repeat new password.</param>
/// <param name="requiresEmailCredits">True, if account needs credits to send emails. Otherwise, false</param>
/// <param name="enableLitmusTest">True, if account is able to send template tests to Litmus. Otherwise, false</param>
/// <param name="requiresLitmusCredits">True, if account needs credits to send emails. Otherwise, false</param>
/// <param name="maxContacts">Maximum number of contacts the account can havelkd</param>
/// <param name="enablePrivateIPRequest">True, if account can request for private IP on its own. Otherwise, false</param>
/// <param name="sendActivation">True, if you want to send activation email to this account. Otherwise, false</param>
/// <param name="returnUrl">URL to navigate to after account creation</param>
/// <param name="sendingPermission">Sending permission setting for account</param>
/// <param name="enableContactFeatures">True, if you want to use Advanced Tools. Otherwise, false</param>
/// <param name="poolName">Private IP required. Name of the custom IP Pool which Sub Account should use to send its emails. Leave empty for the default one or if no Private IPs have been bought</param>
/// <returns>string</returns>
public static string AddSubAccount(string email, string password, string confirmPassword, bool requiresEmailCredits = false, bool enableLitmusTest = false, bool requiresLitmusCredits = false, int maxContacts = 0, bool enablePrivateIPRequest = true, bool sendActivation = false, string returnUrl = null, ApiTypes.SendingPermission? sendingPermission = null, bool? enableContactFeatures = null, string poolName = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("email", email);
values.Add("password", password);
values.Add("confirmPassword", confirmPassword);
if (requiresEmailCredits != false) values.Add("requiresEmailCredits", requiresEmailCredits.ToString());
if (enableLitmusTest != false) values.Add("enableLitmusTest", enableLitmusTest.ToString());
if (requiresLitmusCredits != false) values.Add("requiresLitmusCredits", requiresLitmusCredits.ToString());
if (maxContacts != 0) values.Add("maxContacts", maxContacts.ToString());
if (enablePrivateIPRequest != true) values.Add("enablePrivateIPRequest", enablePrivateIPRequest.ToString());
if (sendActivation != false) values.Add("sendActivation", sendActivation.ToString());
if (returnUrl != null) values.Add("returnUrl", returnUrl);
if (sendingPermission != null) values.Add("sendingPermission", Newtonsoft.Json.JsonConvert.SerializeObject(sendingPermission));
if (enableContactFeatures != null) values.Add("enableContactFeatures", enableContactFeatures.ToString());
if (poolName != null) values.Add("poolName", poolName);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/addsubaccount", values);
ApiResponse<string> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<string>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Add email, template or litmus credits to a sub-account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="credits">Amount of credits to add</param>
/// <param name="notes">Specific notes about the transaction</param>
/// <param name="creditType">Type of credits to add (Email or Litmus)</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to add credits to. Use subAccountEmail or publicAccountID not both.</param>
public static void AddSubAccountCredits(int credits, string notes, ApiTypes.CreditType creditType = ApiTypes.CreditType.Email, string subAccountEmail = null, string publicAccountID = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("credits", credits.ToString());
values.Add("notes", notes);
if (creditType != ApiTypes.CreditType.Email) values.Add("creditType", creditType.ToString());
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/addsubaccountcredits", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Change your email address. Remember, that your email address is used as login!
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="sourceUrl">URL from which request was sent.</param>
/// <param name="newEmail">New email address.</param>
/// <param name="confirmEmail">New email address.</param>
public static void ChangeEmail(string sourceUrl, string newEmail, string confirmEmail)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("sourceUrl", sourceUrl);
values.Add("newEmail", newEmail);
values.Add("confirmEmail", confirmEmail);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/changeemail", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Create new password for your account. Password needs to be at least 6 characters long.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="currentPassword">Current password.</param>
/// <param name="newPassword">New password for account.</param>
/// <param name="confirmPassword">Repeat new password.</param>
public static void ChangePassword(string currentPassword, string newPassword, string confirmPassword)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("currentPassword", currentPassword);
values.Add("newPassword", newPassword);
values.Add("confirmPassword", confirmPassword);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/changepassword", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Deletes specified Subaccount
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="notify">True, if you want to send an email notification. Otherwise, false</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to delete. Use subAccountEmail or publicAccountID not both.</param>
public static void DeleteSubAccount(bool notify = true, string subAccountEmail = null, string publicAccountID = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (notify != true) values.Add("notify", notify.ToString());
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/deletesubaccount", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Returns API Key for the given Sub Account.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to retrieve sub-account API Key. Use subAccountEmail or publicAccountID not both.</param>
/// <returns>string</returns>
public static string GetSubAccountApiKey(string subAccountEmail = null, string publicAccountID = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/getsubaccountapikey", values);
ApiResponse<string> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<string>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists all of your subaccounts
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>List(ApiTypes.SubAccount)</returns>
public static List<ApiTypes.SubAccount> GetSubAccountList()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/getsubaccountlist", values);
ApiResponse<List<ApiTypes.SubAccount>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.SubAccount>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Loads your account. Returns detailed information about your account.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>ApiTypes.Account</returns>
public static ApiTypes.Account Load()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/load", values);
ApiResponse<ApiTypes.Account> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.Account>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Load advanced options of your account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>ApiTypes.AdvancedOptions</returns>
public static ApiTypes.AdvancedOptions LoadAdvancedOptions()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadadvancedoptions", values);
ApiResponse<ApiTypes.AdvancedOptions> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.AdvancedOptions>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists email credits history
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>List(ApiTypes.EmailCredits)</returns>
public static List<ApiTypes.EmailCredits> LoadEmailCreditsHistory()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loademailcreditshistory", values);
ApiResponse<List<ApiTypes.EmailCredits>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.EmailCredits>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists litmus credits history
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>List(ApiTypes.LitmusCredits)</returns>
public static List<ApiTypes.LitmusCredits> LoadLitmusCreditsHistory()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadlitmuscreditshistory", values);
ApiResponse<List<ApiTypes.LitmusCredits>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.LitmusCredits>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows queue of newest notifications - very useful when you want to check what happened with mails that were not received.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>List(ApiTypes.NotificationQueue)</returns>
public static List<ApiTypes.NotificationQueue> LoadNotificationQueue()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadnotificationqueue", values);
ApiResponse<List<ApiTypes.NotificationQueue>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.NotificationQueue>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists all payments
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="limit">Maximum of loaded items.</param>
/// <param name="offset">How many items should be loaded ahead.</param>
/// <param name="fromDate">Starting date for search in YYYY-MM-DDThh:mm:ss format.</param>
/// <param name="toDate">Ending date for search in YYYY-MM-DDThh:mm:ss format.</param>
/// <returns>List(ApiTypes.Payment)</returns>
public static List<ApiTypes.Payment> LoadPaymentHistory(int limit, int offset, DateTime fromDate, DateTime toDate)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("limit", limit.ToString());
values.Add("offset", offset.ToString());
values.Add("fromDate", fromDate.ToString("M/d/yyyy h:mm:ss tt"));
values.Add("toDate", toDate.ToString("M/d/yyyy h:mm:ss tt"));
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadpaymenthistory", values);
ApiResponse<List<ApiTypes.Payment>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.Payment>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists all referral payout history
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>List(ApiTypes.Payment)</returns>
public static List<ApiTypes.Payment> LoadPayoutHistory()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadpayouthistory", values);
ApiResponse<List<ApiTypes.Payment>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.Payment>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows information about your referral details
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>ApiTypes.Referral</returns>
public static ApiTypes.Referral LoadReferralDetails()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadreferraldetails", values);
ApiResponse<ApiTypes.Referral> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.Referral>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows latest changes in your sending reputation
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="limit">Maximum of loaded items.</param>
/// <param name="offset">How many items should be loaded ahead.</param>
/// <returns>List(ApiTypes.ReputationHistory)</returns>
public static List<ApiTypes.ReputationHistory> LoadReputationHistory(int limit = 20, int offset = 0)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (limit != 20) values.Add("limit", limit.ToString());
if (offset != 0) values.Add("offset", offset.ToString());
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadreputationhistory", values);
ApiResponse<List<ApiTypes.ReputationHistory>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.ReputationHistory>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows detailed information about your actual reputation score
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>ApiTypes.ReputationDetail</returns>
public static ApiTypes.ReputationDetail LoadReputationImpact()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadreputationimpact", values);
ApiResponse<ApiTypes.ReputationDetail> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.ReputationDetail>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Returns detailed spam check.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="limit">Maximum of loaded items.</param>
/// <param name="offset">How many items should be loaded ahead.</param>
/// <returns>List(ApiTypes.SpamCheck)</returns>
public static List<ApiTypes.SpamCheck> LoadSpamCheck(int limit = 20, int offset = 0)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (limit != 20) values.Add("limit", limit.ToString());
if (offset != 0) values.Add("offset", offset.ToString());
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadspamcheck", values);
ApiResponse<List<ApiTypes.SpamCheck>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.SpamCheck>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists email credits history for sub-account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to list history for. Use subAccountEmail or publicAccountID not both.</param>
/// <returns>List(ApiTypes.EmailCredits)</returns>
public static List<ApiTypes.EmailCredits> LoadSubAccountsEmailCreditsHistory(string subAccountEmail = null, string publicAccountID = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadsubaccountsemailcreditshistory", values);
ApiResponse<List<ApiTypes.EmailCredits>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.EmailCredits>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Loads settings of subaccount
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to load settings for. Use subAccountEmail or publicAccountID not both.</param>
/// <returns>ApiTypes.SubAccountSettings</returns>
public static ApiTypes.SubAccountSettings LoadSubAccountSettings(string subAccountEmail = null, string publicAccountID = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadsubaccountsettings", values);
ApiResponse<ApiTypes.SubAccountSettings> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.SubAccountSettings>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Lists litmus credits history for sub-account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to list history for. Use subAccountEmail or publicAccountID not both.</param>
/// <returns>List(ApiTypes.LitmusCredits)</returns>
public static List<ApiTypes.LitmusCredits> LoadSubAccountsLitmusCreditsHistory(string subAccountEmail = null, string publicAccountID = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadsubaccountslitmuscreditshistory", values);
ApiResponse<List<ApiTypes.LitmusCredits>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.LitmusCredits>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows usage of your account in given time.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="from">Starting date for search in YYYY-MM-DDThh:mm:ss format.</param>
/// <param name="to">Ending date for search in YYYY-MM-DDThh:mm:ss format.</param>
/// <returns>List(ApiTypes.Usage)</returns>
public static List<ApiTypes.Usage> LoadUsage(DateTime from, DateTime to)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("from", from.ToString("M/d/yyyy h:mm:ss tt"));
values.Add("to", to.ToString("M/d/yyyy h:mm:ss tt"));
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/loadusage", values);
ApiResponse<List<ApiTypes.Usage>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<ApiTypes.Usage>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Manages your apikeys.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="apiKey">APIKey you would like to manage.</param>
/// <param name="action">Specific action you would like to perform on the APIKey</param>
/// <returns>List(string)</returns>
public static List<string> ManageApiKeys(string apiKey, ApiTypes.APIKeyAction action)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("apiKey", apiKey);
values.Add("action", action.ToString());
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/manageapikeys", values);
ApiResponse<List<string>> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<List<string>>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows summary for your account.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>ApiTypes.AccountOverview</returns>
public static ApiTypes.AccountOverview Overview()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/overview", values);
ApiResponse<ApiTypes.AccountOverview> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.AccountOverview>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Shows you account's profile basic overview
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <returns>ApiTypes.Profile</returns>
public static ApiTypes.Profile ProfileOverview()
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/profileoverview", values);
ApiResponse<ApiTypes.Profile> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.Profile>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Remove email, template or litmus credits from a sub-account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="creditType">Type of credits to add (Email or Litmus)</param>
/// <param name="notes">Specific notes about the transaction</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to remove credits from. Use subAccountEmail or publicAccountID not both.</param>
/// <param name="credits">Amount of credits to remove</param>
/// <param name="removeAll">Remove all credits of this type from sub-account (overrides credits if provided)</param>
public static void RemoveSubAccountCredits(ApiTypes.CreditType creditType, string notes, string subAccountEmail = null, string publicAccountID = null, int? credits = null, bool removeAll = false)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("creditType", creditType.ToString());
values.Add("notes", notes);
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
if (credits != null) values.Add("credits", credits.ToString());
if (removeAll != false) values.Add("removeAll", removeAll.ToString());
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/removesubaccountcredits", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Request a private IP for your Account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="count">Number of items.</param>
/// <param name="notes">Free form field of notes</param>
public static void RequestPrivateIP(int count, string notes)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("count", count.ToString());
values.Add("notes", notes);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/requestprivateip", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Update sending and tracking options of your account.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="enableClickTracking">True, if you want to track clicks. Otherwise, false</param>
/// <param name="enableLinkClickTracking">True, if you want to track by link tracking. Otherwise, false</param>
/// <param name="manageSubscriptions">True, if you want to display your labels on your unsubscribe form. Otherwise, false</param>
/// <param name="manageSubscribedOnly">True, if you want to only display labels that the contact is subscribed to on your unsubscribe form. Otherwise, false</param>
/// <param name="transactionalOnUnsubscribe">True, if you want to display an option for the contact to opt into transactional email only on your unsubscribe form. Otherwise, false</param>
/// <param name="skipListUnsubscribe">True, if you do not want to use list-unsubscribe headers. Otherwise, false</param>
/// <param name="autoTextFromHtml">True, if text BODY of message should be created automatically. Otherwise, false</param>
/// <param name="allowCustomHeaders">True, if you want to apply custom headers to your emails. Otherwise, false</param>
/// <param name="bccEmail">Email address to send a copy of all email to.</param>
/// <param name="contentTransferEncoding">Type of content encoding</param>
/// <param name="emailNotificationForError">True, if you want bounce notifications returned. Otherwise, false</param>
/// <param name="emailNotificationEmail">Specific email address to send bounce email notifications to.</param>
/// <param name="webNotificationUrl">URL address to receive web notifications to parse and process.</param>
/// <param name="webNotificationForSent">True, if you want to send web notifications for sent email. Otherwise, false</param>
/// <param name="webNotificationForOpened">True, if you want to send web notifications for opened email. Otherwise, false</param>
/// <param name="webNotificationForClicked">True, if you want to send web notifications for clicked email. Otherwise, false</param>
/// <param name="webNotificationForUnsubscribed">True, if you want to send web notifications for unsubscribed email. Otherwise, false</param>
/// <param name="webNotificationForAbuseReport">True, if you want to send web notifications for complaint email. Otherwise, false</param>
/// <param name="webNotificationForError">True, if you want to send web notifications for bounced email. Otherwise, false</param>
/// <param name="hubCallBackUrl">URL used for tracking action of inbound emails</param>
/// <param name="inboundDomain">Domain you use as your inbound domain</param>
/// <param name="inboundContactsOnly">True, if you want inbound email to only process contacts from your account. Otherwise, false</param>
/// <param name="lowCreditNotification">True, if you want to receive low credit email notifications. Otherwise, false</param>
/// <param name="enableUITooltips">True, if account has tooltips active. Otherwise, false</param>
/// <param name="enableContactFeatures">True, if you want to use Advanced Tools. Otherwise, false</param>
/// <param name="notificationsEmails">Email addresses to send a copy of all notifications from our system. Separated by semicolon</param>
/// <param name="unsubscribeNotificationsEmails">Emails, separated by semicolon, to which the notification about contact unsubscribing should be sent to</param>
/// <param name="logoUrl">URL to your logo image.</param>
/// <param name="enableTemplateScripting">True, if you want to use template scripting in your emails {{}}. Otherwise, false</param>
/// <param name="staleContactScore">(0 means this functionality is NOT enabled) Score, depending on the number of times you have sent to a recipient, at which the given recipient should be moved to the Stale status</param>
/// <param name="staleContactInactiveDays"></param>
/// <returns>ApiTypes.AdvancedOptions</returns>
public static ApiTypes.AdvancedOptions UpdateAdvancedOptions(bool? enableClickTracking = null, bool? enableLinkClickTracking = null, bool? manageSubscriptions = null, bool? manageSubscribedOnly = null, bool? transactionalOnUnsubscribe = null, bool? skipListUnsubscribe = null, bool? autoTextFromHtml = null, bool? allowCustomHeaders = null, string bccEmail = null, string contentTransferEncoding = null, bool? emailNotificationForError = null, string emailNotificationEmail = null, string webNotificationUrl = null, bool? webNotificationForSent = null, bool? webNotificationForOpened = null, bool? webNotificationForClicked = null, bool? webNotificationForUnsubscribed = null, bool? webNotificationForAbuseReport = null, bool? webNotificationForError = null, string hubCallBackUrl = "", string inboundDomain = null, bool? inboundContactsOnly = null, bool? lowCreditNotification = null, bool? enableUITooltips = null, bool? enableContactFeatures = null, string notificationsEmails = null, string unsubscribeNotificationsEmails = null, string logoUrl = null, bool? enableTemplateScripting = true, int? staleContactScore = null, int? staleContactInactiveDays = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (enableClickTracking != null) values.Add("enableClickTracking", enableClickTracking.ToString());
if (enableLinkClickTracking != null) values.Add("enableLinkClickTracking", enableLinkClickTracking.ToString());
if (manageSubscriptions != null) values.Add("manageSubscriptions", manageSubscriptions.ToString());
if (manageSubscribedOnly != null) values.Add("manageSubscribedOnly", manageSubscribedOnly.ToString());
if (transactionalOnUnsubscribe != null) values.Add("transactionalOnUnsubscribe", transactionalOnUnsubscribe.ToString());
if (skipListUnsubscribe != null) values.Add("skipListUnsubscribe", skipListUnsubscribe.ToString());
if (autoTextFromHtml != null) values.Add("autoTextFromHtml", autoTextFromHtml.ToString());
if (allowCustomHeaders != null) values.Add("allowCustomHeaders", allowCustomHeaders.ToString());
if (bccEmail != null) values.Add("bccEmail", bccEmail);
if (contentTransferEncoding != null) values.Add("contentTransferEncoding", contentTransferEncoding);
if (emailNotificationForError != null) values.Add("emailNotificationForError", emailNotificationForError.ToString());
if (emailNotificationEmail != null) values.Add("emailNotificationEmail", emailNotificationEmail);
if (webNotificationUrl != null) values.Add("webNotificationUrl", webNotificationUrl);
if (webNotificationForSent != null) values.Add("webNotificationForSent", webNotificationForSent.ToString());
if (webNotificationForOpened != null) values.Add("webNotificationForOpened", webNotificationForOpened.ToString());
if (webNotificationForClicked != null) values.Add("webNotificationForClicked", webNotificationForClicked.ToString());
if (webNotificationForUnsubscribed != null) values.Add("webNotificationForUnsubscribed", webNotificationForUnsubscribed.ToString());
if (webNotificationForAbuseReport != null) values.Add("webNotificationForAbuseReport", webNotificationForAbuseReport.ToString());
if (webNotificationForError != null) values.Add("webNotificationForError", webNotificationForError.ToString());
if (hubCallBackUrl != "") values.Add("hubCallBackUrl", hubCallBackUrl);
if (inboundDomain != null) values.Add("inboundDomain", inboundDomain);
if (inboundContactsOnly != null) values.Add("inboundContactsOnly", inboundContactsOnly.ToString());
if (lowCreditNotification != null) values.Add("lowCreditNotification", lowCreditNotification.ToString());
if (enableUITooltips != null) values.Add("enableUITooltips", enableUITooltips.ToString());
if (enableContactFeatures != null) values.Add("enableContactFeatures", enableContactFeatures.ToString());
if (notificationsEmails != null) values.Add("notificationsEmails", notificationsEmails);
if (unsubscribeNotificationsEmails != null) values.Add("unsubscribeNotificationsEmails", unsubscribeNotificationsEmails);
if (logoUrl != null) values.Add("logoUrl", logoUrl);
if (enableTemplateScripting != true) values.Add("enableTemplateScripting", enableTemplateScripting.ToString());
if (staleContactScore != null) values.Add("staleContactScore", staleContactScore.ToString());
if (staleContactInactiveDays != null) values.Add("staleContactInactiveDays", staleContactInactiveDays.ToString());
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/updateadvancedoptions", values);
ApiResponse<ApiTypes.AdvancedOptions> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<ApiTypes.AdvancedOptions>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
return apiRet.Data;
}
/// <summary>
/// Update settings of your private branding. These settings are needed, if you want to use Elastic Email under your brand.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="enablePrivateBranding">True: Turn on or off ability to send mails under your brand. Otherwise, false</param>
/// <param name="logoUrl">URL to your logo image.</param>
/// <param name="supportLink">Address to your support.</param>
/// <param name="privateBrandingUrl">Subdomain for your rebranded service</param>
/// <param name="smtpAddress">Address of SMTP server.</param>
/// <param name="smtpAlternative">Address of alternative SMTP server.</param>
/// <param name="paymentUrl">URL for making payments.</param>
public static void UpdateCustomBranding(bool enablePrivateBranding = false, string logoUrl = null, string supportLink = null, string privateBrandingUrl = null, string smtpAddress = null, string smtpAlternative = null, string paymentUrl = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (enablePrivateBranding != false) values.Add("enablePrivateBranding", enablePrivateBranding.ToString());
if (logoUrl != null) values.Add("logoUrl", logoUrl);
if (supportLink != null) values.Add("supportLink", supportLink);
if (privateBrandingUrl != null) values.Add("privateBrandingUrl", privateBrandingUrl);
if (smtpAddress != null) values.Add("smtpAddress", smtpAddress);
if (smtpAlternative != null) values.Add("smtpAlternative", smtpAlternative);
if (paymentUrl != null) values.Add("paymentUrl", paymentUrl);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/updatecustombranding", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Update http notification URL.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="url">URL of notification.</param>
/// <param name="settings">Http notification settings serialized to JSON </param>
public static void UpdateHttpNotification(string url, string settings = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("url", url);
if (settings != null) values.Add("settings", settings);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/updatehttpnotification", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Update your profile.
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="firstName">First name.</param>
/// <param name="lastName">Last name.</param>
/// <param name="address1">First line of address.</param>
/// <param name="city">City.</param>
/// <param name="state">State or province.</param>
/// <param name="zip">Zip/postal code.</param>
/// <param name="countryID">Numeric ID of country. A file with the list of countries is available <a href="http://api.elasticemail.com/public/countries"><b>here</b></a></param>
/// <param name="deliveryReason">Why your clients are receiving your emails.</param>
/// <param name="marketingConsent">True if you want to receive newsletters from Elastic Email. Otherwise, false.</param>
/// <param name="address2">Second line of address.</param>
/// <param name="company">Company name.</param>
/// <param name="website">HTTP address of your website.</param>
/// <param name="logoUrl">URL to your logo image.</param>
/// <param name="taxCode">Code used for tax purposes.</param>
/// <param name="phone">Phone number</param>
public static void UpdateProfile(string firstName, string lastName, string address1, string city, string state, string zip, int countryID, string deliveryReason = null, bool marketingConsent = false, string address2 = null, string company = null, string website = null, string logoUrl = null, string taxCode = null, string phone = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("firstName", firstName);
values.Add("lastName", lastName);
values.Add("address1", address1);
values.Add("city", city);
values.Add("state", state);
values.Add("zip", zip);
values.Add("countryID", countryID.ToString());
if (deliveryReason != null) values.Add("deliveryReason", deliveryReason);
if (marketingConsent != false) values.Add("marketingConsent", marketingConsent.ToString());
if (address2 != null) values.Add("address2", address2);
if (company != null) values.Add("company", company);
if (website != null) values.Add("website", website);
if (logoUrl != null) values.Add("logoUrl", logoUrl);
if (taxCode != null) values.Add("taxCode", taxCode);
if (phone != null) values.Add("phone", phone);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/updateprofile", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
/// <summary>
/// Updates settings of specified subaccount
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="requiresEmailCredits">True, if account needs credits to send emails. Otherwise, false</param>
/// <param name="monthlyRefillCredits">Amount of credits added to account automatically</param>
/// <param name="requiresLitmusCredits">True, if account needs credits to send emails. Otherwise, false</param>
/// <param name="enableLitmusTest">True, if account is able to send template tests to Litmus. Otherwise, false</param>
/// <param name="dailySendLimit">Amount of emails account can send daily</param>
/// <param name="emailSizeLimit">Maximum size of email including attachments in MB's</param>
/// <param name="enablePrivateIPRequest">True, if account can request for private IP on its own. Otherwise, false</param>
/// <param name="maxContacts">Maximum number of contacts the account can havelkd</param>
/// <param name="subAccountEmail">Email address of sub-account</param>
/// <param name="publicAccountID">Public key of sub-account to update. Use subAccountEmail or publicAccountID not both.</param>
/// <param name="sendingPermission">Sending permission setting for account</param>
/// <param name="enableContactFeatures">True, if you want to use Advanced Tools. Otherwise, false</param>
/// <param name="poolName">Name of your custom IP Pool to be used in the sending process</param>
public static void UpdateSubAccountSettings(bool requiresEmailCredits = false, int monthlyRefillCredits = 0, bool requiresLitmusCredits = false, bool enableLitmusTest = false, int dailySendLimit = 50, int emailSizeLimit = 10, bool enablePrivateIPRequest = false, int maxContacts = 0, string subAccountEmail = null, string publicAccountID = null, ApiTypes.SendingPermission? sendingPermission = null, bool? enableContactFeatures = null, string poolName = null)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
if (requiresEmailCredits != false) values.Add("requiresEmailCredits", requiresEmailCredits.ToString());
if (monthlyRefillCredits != 0) values.Add("monthlyRefillCredits", monthlyRefillCredits.ToString());
if (requiresLitmusCredits != false) values.Add("requiresLitmusCredits", requiresLitmusCredits.ToString());
if (enableLitmusTest != false) values.Add("enableLitmusTest", enableLitmusTest.ToString());
if (dailySendLimit != 50) values.Add("dailySendLimit", dailySendLimit.ToString());
if (emailSizeLimit != 10) values.Add("emailSizeLimit", emailSizeLimit.ToString());
if (enablePrivateIPRequest != false) values.Add("enablePrivateIPRequest", enablePrivateIPRequest.ToString());
if (maxContacts != 0) values.Add("maxContacts", maxContacts.ToString());
if (subAccountEmail != null) values.Add("subAccountEmail", subAccountEmail);
if (publicAccountID != null) values.Add("publicAccountID", publicAccountID);
if (sendingPermission != null) values.Add("sendingPermission", Newtonsoft.Json.JsonConvert.SerializeObject(sendingPermission));
if (enableContactFeatures != null) values.Add("enableContactFeatures", enableContactFeatures.ToString());
if (poolName != null) values.Add("poolName", poolName);
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/account/updatesubaccountsettings", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));
if (!apiRet.success) throw new ApplicationException(apiRet.error);
}
}
#endregion
#region Attachment functions
/// <summary>
/// Managing attachments uploaded to your account.
/// </summary>
public static class Attachment
{
/// <summary>
/// Permanently deletes attachment file from your account
/// </summary>
/// <param name="apikey">ApiKey that gives you access to our SMTP and HTTP API's.</param>
/// <param name="attachmentID">ID number of your attachment.</param>
public static void Delete(long attachmentID)
{
WebClient client = new CustomWebClient();
NameValueCollection values = new NameValueCollection();
values.Add("apikey", Api.ApiKey);
values.Add("attachmentID", attachmentID.ToString());
byte[] apiResponse = client.UploadValues(Api.ApiUri + "/attachment/delete", values);
ApiResponse<VoidApiResponse> apiRet = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiResponse<VoidApiResponse>>(Encoding.UTF8.GetString(apiResponse));