Ejemplo n.º 1
0
        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}");
        }
Ejemplo n.º 2
0
        public void getCampaigns()
        {
            getCampaigns function = new getCampaigns()
            {
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 3
0
        private AbstractMailrelayReply TestCall(AbstractFunction functionToCall)
        {
            AbstractMailrelayReply reply = _mailrelayConnection.Send(functionToCall);

            Console.Out.WriteLine(functionToCall.ToGet());
            Console.Out.WriteLine(reply.ToJson());

            return(reply);
        }
Ejemplo n.º 4
0
        public void getStats()
        {
            getStats function = new getStats()
            {
                startDate = DateTime.Now.AddDays(1), endDate = DateTime.Now
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 5
0
        public void deleteGroup()
        {
            deleteGroup function = new deleteGroup()
            {
                id = 2
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 6
0
        public void deleteSubscriber()
        {
            deleteSubscriber function = new deleteSubscriber()
            {
                email = "*****@*****.**"
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 7
0
        public void getMailRcptInfo()
        {
            getMailRcptInfo function = new getMailRcptInfo()
            {
                id = 1, email = "*****@*****.**", date = DateTime.Now
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        public void getPackages()
        {
            getPackages function = new getPackages()
            {
                sortOrder = AbstractFunction.sortOrderEnum.DESC
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        public void getDayLog()
        {
            getDayLog function = new getDayLog()
            {
                count = 10
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 13
0
        public void getSmtpTags()
        {
            getSmtpTags function = new getSmtpTags()
            {
                count = 10, offset = 0
            };
            AbstractMailrelayReply reply = TestCall(function);

            Assert.AreEqual(1, reply.status);
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 public MailrelayConnectionException(AbstractFunction senderFunction, AbstractMailrelayReply reply, string targetUrl, Exception inner)
     : base($"Error:	{inner.Message}" + GetMessage(senderFunction, reply, targetUrl), inner)
 {
 }
Ejemplo n.º 25
0
 public MailrelayConnectionException(AbstractFunction senderFunction, AbstractMailrelayReply reply, string targetUrl)
     : base(GetMessage(senderFunction, reply, targetUrl))
 {
 }