private static string GetMessage(AbstractFunction senderFunction, AbstractMailrelayReply reply, string targetUrl) { string parameters = senderFunction.ToGet(); string error = reply.error; return($"{senderFunction.GetType().Name}{Environment.NewLine} Url:{targetUrl}{Environment.NewLine} Parameters:{parameters}{Environment.NewLine} Error:{error}"); }
public void getCampaigns() { getCampaigns function = new getCampaigns() { }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
private AbstractMailrelayReply TestCall(AbstractFunction functionToCall) { AbstractMailrelayReply reply = _mailrelayConnection.Send(functionToCall); Console.Out.WriteLine(functionToCall.ToGet()); Console.Out.WriteLine(reply.ToJson()); return(reply); }
public void getStats() { getStats function = new getStats() { startDate = DateTime.Now.AddDays(1), endDate = DateTime.Now }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void deleteGroup() { deleteGroup function = new deleteGroup() { id = 2 }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void deleteSubscriber() { deleteSubscriber function = new deleteSubscriber() { email = "*****@*****.**" }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void getMailRcptInfo() { getMailRcptInfo function = new getMailRcptInfo() { id = 1, email = "*****@*****.**", date = DateTime.Now }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void addGroup() { addGroup function = new addGroup() { description = "this is a test group", enable = false, name = "test", position = 3, visible = true }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void getPackages() { getPackages function = new getPackages() { sortOrder = AbstractFunction.sortOrderEnum.DESC }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void updateCustomField() { updateCustomField function = new updateCustomField() { id = 1, defaultField = "testDefault", enable = true, fieldType = AbstractCustomField.CustomFieldTypeEnum.TextField, name = "test", position = 1 }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void updateGroup() { updateGroup function = new updateGroup() { id = 2, description = "this is test group 2", enable = false, name = "test", visible = true, position = 4 }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void getDayLog() { getDayLog function = new getDayLog() { count = 10 }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void getSmtpTags() { getSmtpTags function = new getSmtpTags() { count = 10, offset = 0 }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public AbstractMailrelayReply GetMailrelayReply(string replyString) { try { AbstractMailrelayReply reply = JsonConvert.DeserializeObject(replyString, ReturnType, new DateTimeConverter()) as AbstractMailrelayReply; return(reply); } catch (Exception exception) { throw new Exception($"Failed DeserializeObject {replyString}", exception); } }
public void updateSubscribers() { updateSubscribers function = new updateSubscribers() { ids = new List <int>() { 2 }, activated = true, banned = false, deleted = false }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
private void UpdateSubscriber(int id, string email, Dictionary <string, string> customFieldsResult, List <int> groups, string fullname) { updateSubscriber update = new updateSubscriber() { customFields = customFieldsResult, email = email, name = fullname, groups = groups, id = id, }; AbstractMailrelayReply reply = _mailrelayConnection.Send(update); }
public AbstractMailrelayReply Send(AbstractFunction functionToSend) { if (replies.Count == 0) { throw new Exception($"reply queue was empty when sending {HttpUtility.UrlDecode(functionToSend.ToGet())}"); } sendFunctions.Add(functionToSend); AbstractMailrelayReply reply = replies.Dequeue(); return(reply); }
public MailrelayBoolReply UpdateFromReply(getSubscribersReply replyToUpdate) { updateSubscriber update = new updateSubscriber() { customFields = replyToUpdate.fields, email = replyToUpdate.email, name = replyToUpdate.name, groups = replyToUpdate.groups.Select(groupString => int.Parse(groupString)).ToList(), id = int.Parse(replyToUpdate.id), }; AbstractMailrelayReply reply = _mailrelayConnection.Send(update); return((MailrelayBoolReply)reply); }
public void assignSubscribersToGroups() { assignSubscribersToGroups function = new assignSubscribersToGroups() { groups = new List <int>() { 3 }, subscribers = new List <string>() { "[email protected]_test2" } }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public AbstractMailrelayReply Send(AbstractFunction functionToSend) { functionToSend.apiKey = mailrelayApiKey; string target = mailrelayUrl + functionToSend.ToGet(); Dictionary <string, string> values = functionToSend.GetValues(); string reply; using (HttpClient client = new HttpClient()) { FormUrlEncodedContent content = new FormUrlEncodedContent(values); if (DateTime.Now < lastSend + sendInterval) { Thread.Sleep(sendInterval); } lastSend = DateTime.Now; try { Task <HttpResponseMessage> response = client.PostAsync(mailrelayUrl, content); Task <string> responseString = response.Result.Content.ReadAsStringAsync(); reply = responseString.Result; } catch (Exception exception) { while (exception.InnerException != null) { exception = exception.InnerException; } throw new MailrelayConnectionException(functionToSend, mailrelayUrl, exception); } } AbstractMailrelayReply mailrelayReply = functionToSend.GetMailrelayReply(reply); if (mailrelayReply.status == 0) { throw new MailrelayConnectionException(functionToSend, mailrelayReply, mailrelayUrl); } return(mailrelayReply); }
public void sendMail() { sendMail function = new sendMail() { emails = new Dictionary <string, string>() { { "Svend", "*****@*****.**" } }, subject = "test", html = "hej [name] vi tester igen", mailboxFromId = 1, mailboxReplyId = 1, mailboxReportId = 1, packageId = 6, }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public void addSubscriber() { addSubscriber function = new addSubscriber() { email = "*****@*****.**", groups = new List <int>() { 1 }, name = "test_name", customFields = new Dictionary <string, string>() { { "f_1", "f1" }, { "f_3", "f3" }, { "f_4", "f4" }, { "f_5", "f5" }, }, }; AbstractMailrelayReply reply = TestCall(function); Assert.AreEqual(1, reply.status); }
public AbstractMailrelayReply SendAsGet(AbstractFunction functionToSend) { functionToSend.apiKey = mailrelayApiKey; string target = mailrelayUrl + functionToSend.ToGet(); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(target); httpWebRequest.ContentType = "text/xml; encoding='utf-8'"; httpWebRequest.Method = "GET"; HttpWebResponse httpResponse; try { httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); } catch (Exception exception) { throw new MailrelayConnectionException(functionToSend, mailrelayUrl, exception); } string reply; using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream())) { reply = streamReader.ReadToEnd(); } AbstractMailrelayReply mailrelayReply = functionToSend.GetMailrelayReply(reply); if (mailrelayReply.status == 0) { throw new MailrelayConnectionException(functionToSend, mailrelayReply, mailrelayUrl); } return(mailrelayReply); }
public MailrelayConnectionException(AbstractFunction senderFunction, AbstractMailrelayReply reply, string targetUrl, Exception inner) : base($"Error: {inner.Message}" + GetMessage(senderFunction, reply, targetUrl), inner) { }
public MailrelayConnectionException(AbstractFunction senderFunction, AbstractMailrelayReply reply, string targetUrl) : base(GetMessage(senderFunction, reply, targetUrl)) { }