Exemple #1
0
        public SendResponse RunExample()
        {
            var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
            {
                EndpointUrl = ExampleConfig.TargetApi
            };

            //Retrieve data from the datasource
            var customerRepository = new CustomerRepository();
            var customers          = customerRepository.GetCustomers();

            //Build the message
            var message = new BulkMessage();

            message.Subject       = "Hello %%FirstName%%";
            message.PlainTextBody = "Hello %%FirstName%% %%LastName%%. Is your favorite color still %%FavoriteColor%%?";
            message.From.Email    = "*****@*****.**";
            message.ReplyTo.Email = "*****@*****.**";

            //Merge in the customers from the datasource
            foreach (var customer in customers)
            {
                var recipient = new BulkRecipient(customer.EmailAddress);
                recipient.MergeData.Add("FirstName", customer.FirstName);
                recipient.MergeData.Add("LastName", customer.LastName);
                recipient.MergeData.Add("FavoriteColor", customer.FavoriteColor);

                message.To.Add(recipient);
            }

            return(client.Send(message));
        }
Exemple #2
0
        public async Task <OutputResponse> SendMessage(MessageModel message)
        {
            var result = new OutputResponse
            {
                IsErrorOccured = false
            };
            var hasRecipient = false;
            var emailMessage = new BulkMessage();

            emailMessage.Subject    = message.Subject;
            emailMessage.HtmlBody   = message.MessageBody;
            emailMessage.From.Email = message.SourceAddress;

            foreach (var recipient in message.DestinationRecipients)
            {
                if (!string.IsNullOrEmpty(recipient))
                {
                    emailMessage.To.Add(recipient);
                    hasRecipient = true;
                }
            }

            // Only send email if they are actual recipients
            if (hasRecipient)
            {
                await _client.SendAsync(emailMessage);

                result.Message = "Email sent successfully";
            }
            else
            {
                result.Message = "No emails could be found";
            }
            return(result);
        }
 private void HandleInvalidNumbers(BulkMessage bulkMessage)
 {
     foreach (var item in bulkMessage.InvalidReceivers)
     {
         ResultDetailTxt.AppendText(string.Format("{0}\t{1}\r\n", item, "Is invalid number"));
     }
 }
Exemple #4
0
        public SendResponse RunExample()
        {
            var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
            {
                EndpointUrl = ExampleConfig.TargetApi
            };

            var message = new BulkMessage();

            // Add some global merge data
            message.GlobalMergeData.Add("Motto", "When hitting the Inbox matters!");

            message.Subject  = "Sending A BulkSend with MergeData";
            message.HtmlBody = "<html>" +
                               "<head><title>Merge Data Example</title></head>" +
                               "<body>" +
                               "     <h1>Global Merge Data</h1>" +
                               "     <p>CompanyMotto = %%Motto%%</p>" +
                               "     <h1>Per Recipient Merge Data</h1>" +
                               "     <p>EyeColor = %%EyeColor%%</p>" +
                               "     <p>HairColor = %%HairColor%%</p>" +
                               "</body>" +
                               "</html>";
            message.PlainTextBody = "Global Merge Data" +
                                    "CompanyMotto = %%Motto%%" +
                                    "     " +
                                    "Per Recipient Merge Data" +
                                    "     EyeColor = %%EyeColor%%" +
                                    "     HairColor = %%HairColor%%";

            message.From.Email    = "*****@*****.**";
            message.ReplyTo.Email = "*****@*****.**";

            // Add recipients with MergeData
            var mergeDataFor1 = new Dictionary <string, string>();

            mergeDataFor1.Add("EyeColor", "Blue");
            mergeDataFor1.Add("HairColor", "Blond");

            message.To.Add("*****@*****.**", mergeDataFor1);

            var recipient2 = message.To.Add("*****@*****.**", "Recipient #1");

            recipient2.MergeData.Add("EyeColor", "Green");
            recipient2.MergeData.Add("HairColor", "Brown");

            var recipient3 = new BulkRecipient("*****@*****.**");

            recipient3.AddMergeFields("EyeColor", "Hazel");
            recipient3.AddMergeFields("HairColor", "Black");
            message.To.Add(recipient3);

            return(client.Send(message));
        }
Exemple #5
0
        public void Constractor_of_BulkMessage_ShouldSetNumberToInvalidReceivers(string number)
        {
            //Arrange
            List <string> receivers = new List <string>();

            receivers.Add(number);

            //Act
            var bulkMessage = new BulkMessage("salam", receivers, "salam");

            //Assert
            bulkMessage.ValidReceivers.Count.Should().Be(0);
            bulkMessage.InvalidReceivers.Count.Should().Be(1);
        }
Exemple #6
0
        public void ValidateRecipients_BulkMessage_ReturnsNoRecipients_WhenToIsEmpty()
        {
            //Arrange
            var message = new BulkMessage {
                To = new List <IBulkRecipient>()
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.ValidateRecipients(message);

            //Assert
            Assert.AreEqual(SendResult.RecipientValidationMissingTo, actual.Result);
        }
 private void SendBtn_Click(object sender, EventArgs e)
 {
     try
     {
         reader.SetPath(NumbersFilePath);
         var bulkMessage = new BulkMessage(this.ResultPath, reader.Read(), MessageTxt.Text);
         HandleInvalidNumbers(bulkMessage);
         bulkMessageSender.Send(bulkMessage);
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Exception",
                         MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
     }
 }
Exemple #8
0
        public void SendList_Of_BulkMessageSender_Should_Send_When_EveryThingIsOk()
        {
            //Arrange
            List <string> phoneNumbers = new List <string>();

            phoneNumbers.Add("09132204079");
            BulkMessage bulkMessage = new BulkMessage("Salam", phoneNumbers, "سلام");
            //Act
            var result = bulkMessageSender.Send(bulkMessage);

            //Assert
            result.Should().NotBeNull();
            result[0].Status.Should().Be(ResultStatus.Successful);
            OneStepTriggered.Should().BeTrue();
        }
Exemple #9
0
        public void ValidateRecipients_BulkMessage_ReturnsTooManyRecipients_WhenToHasToManyRecipients()
        {
            //Arrange
            var validator = new SendValidator();
            var message   = new BulkMessage
            {
                To = RandomHelper.RandomListOfBulkRecipients(validator.MaximumRecipientsPerMessage + 1)
            };

            //Act
            var actual = validator.ValidateRecipients(message);

            //Assert
            Assert.AreEqual(SendResult.RecipientValidationMaxExceeded, actual.Result);
        }
Exemple #10
0
        public void HasInvalidRecipients_IBulkMessage_ReturnsListOfOne_WhenToHasOneInvalid()
        {
            //Arrange
            var message = new BulkMessage
            {
                To = new List <IBulkRecipient> {
                    new BulkRecipient(RandomHelper.RandomString())
                }
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasInvalidRecipients(message);

            //Assert
            Assert.AreEqual(1, actual.Count);
        }
Exemple #11
0
        public void SendList_Of_BulkMessageSender_Should_Send_When_NumberIsDuplicateButBulkTitleIsDifferent()
        {
            //Arrange
            List <string> phoneNumbers = new List <string>();

            phoneNumbers.Add("09132204079");
            BulkMessage bulkMessage = new BulkMessage("Salam", phoneNumbers, "سلام");

            bulkMessageSender.Send(bulkMessage);
            //Act
            BulkMessage bulkMessage2 = new BulkMessage("Ali", phoneNumbers, "علی");
            var         result       = bulkMessageSender.Send(bulkMessage2);

            //Assert
            result.Should().NotBeNull();
            result[0].Status.Should().Be(ResultStatus.Successful);
            OneStepTriggered.Should().BeTrue();
        }
        public SendResponse RunExample()
        {
            var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
            {
                EndpointUrl = ExampleConfig.TargetApi
            };

            var message = new BulkMessage();

            message.CharSet = "ASCII";

            message.Subject  = "Sending A BulkSend with MergeData";
            message.HtmlBody = "<html>" +
                               "<head><title>ASCII Merge Data Example</title></head>" +
                               "<body>" +
                               "     <h1>Merge Data</h1>" +
                               "     <p>Complete? = %%Complete%%</p>" +
                               "</body>" +
                               "</html>";
            message.PlainTextBody = "Merge Data" +
                                    "     Complete? = %%Complete%%";

            message.From.Email    = "*****@*****.**";
            message.ReplyTo.Email = "*****@*****.**";

            var mergeDataFor1 = new Dictionary <string, string>
            {
                { "Complete", "✔" }
            };

            message.To.Add("*****@*****.**", mergeDataFor1);

            var recipient2 = message.To.Add("*****@*****.**", "Recipient #2");

            recipient2.MergeData.Add("Complete", "✔");

            var recipient3 = new BulkRecipient("*****@*****.**");

            recipient3.MergeData.Add("Complete", "✘");
            message.To.Add(recipient3);

            return(client.Send(message));
        }
        public SendResponse RunExample()
        {
            var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
            {
                EndpointUrl = ExampleConfig.TargetApi
            };

            // Build the message
            var message = new BulkMessage();

            message.Subject = "Sending A Test Message";
            // HtmlBody will be shown if Amp is not supported/not implemented properly
            message.HtmlBody = "<html>This Html Body of my message.</html>";
            message.AmpBody  = "<!doctype html>" +
                               "<html amp4email>" +
                               "<head>" +
                               "  <meta charset=\"utf-8\">" +
                               "  <script async src=\"https://cdn.ampproject.org/v0.js\"></script>" +
                               "  <style amp4email-boilerplate>body{visibility:hidden}</style>" +
                               "  <style amp-custom>" +
                               "    h1 {" +
                               "      margin: 1rem;" +
                               "    }" +
                               "  </style>" +
                               "</head>" +
                               "<body>" +
                               "  <h1>This is the AMP Html Body of my message</h1>" +
                               "</body>" +
                               "</html>";

            // Add recipients
            message.To.Add("*****@*****.**");
            message.To.Add("*****@*****.**", "Recipient #2");
            message.To.Add(new BulkRecipient("*****@*****.**"));
            message.To.Add(new BulkRecipient("*****@*****.**", "Recipient #4"));

            // Set other properties as needed
            message.From.Email    = "*****@*****.**";
            message.ReplyTo.Email = "*****@*****.**";

            // Send message
            return(client.Send(message));
        }
Exemple #14
0
        public void HasInvalidRecipients_IBulkMessage_ReturnsNull_WhenNoInvalidRecipientsFound()
        {
            //Arrange
            var message = new BulkMessage
            {
                To = new List <IBulkRecipient>
                {
                    new BulkRecipient(RandomHelper.RandomEmail()),
                    new BulkRecipient(RandomHelper.RandomEmail()),
                    new BulkRecipient(RandomHelper.RandomEmail())
                }
            };
            var validator = new SendValidator();

            //Act
            var actual = validator.HasInvalidRecipients(message);

            //Assert
            Assert.AreEqual(0, actual.Count);
        }
Exemple #15
0
        public void SendList_Of_BulkMessageSender_Should_NotSend_When_NumberIsDuplicateWhenWeRefineItForBulkMessage()
        {
            //Arrange
            List <string> phoneNumbers = new List <string>();

            phoneNumbers.Add("09132204079");
            BulkMessage bulkMessage = new BulkMessage("Salam", phoneNumbers, "سلام");

            bulkMessageSender.Send(bulkMessage);
            //Act
            List <string> phoneNumbers2 = new List <string>();

            phoneNumbers2.Add("9132204079");
            BulkMessage bulkMessage2 = new BulkMessage("Salam", phoneNumbers2, "سلام");
            var         result       = bulkMessageSender.Send(bulkMessage2);

            //Assert
            result.Should().NotBeNull();
            result[0].Status.Should().Be(ResultStatus.IsDuplicate);
            OneStepTriggered.Should().BeTrue();
        }
        public SendResponse RunExample()
        {
            var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
            {
                EndpointUrl = ExampleConfig.TargetApi
            };

            var message = new BulkMessage();

            message.Subject       = "Sending A Test Message";
            message.HtmlBody      = "<html>This is the Html Body of my message.</html>";
            message.PlainTextBody = "This is the Plain Text Body of my message.";

            message.From.Email    = "*****@*****.**";
            message.ReplyTo.Email = "*****@*****.**";

            message.To.Add("*****@*****.**");
            message.To.Add("*****@*****.**", "Recipient #1");
            message.To.Add(new BulkRecipient("*****@*****.**"));
            message.To.Add(new BulkRecipient("*****@*****.**", "Recipient #4"));

            return(client.Send(message));
        }
        public SendResponse RunExample()
        {
            var client = new SocketLabsClient(ExampleConfig.ServerId, ExampleConfig.ApiKey)
            {
                EndpointUrl = ExampleConfig.TargetApi
            };

            // Build the message
            var message = new BulkMessage();

            // Add some global merge-data (These will be applied to all Recipients unless specifically overridden by Recipient level merge-data)
            message.GlobalMergeData.Add("Motto", "When hitting the Inbox matters!");
            message.GlobalMergeData.Add("Birthday", "Unknown");
            message.GlobalMergeData.Add("Age", "an unknown number of");
            message.GlobalMergeData.Add("UpSell", "BTW:  You are eligible for discount pricing when you upgrade your service!");

            // Add recipients with merge data
            var recipient1 = message.To.Add("*****@*****.**");

            recipient1.MergeData.Add("Birthday", "08/05/1991");
            recipient1.MergeData.Add("Age", "27");

            var recipient2 = message.To.Add("*****@*****.**");

            recipient2.MergeData.Add("Birthday", "04/12/1984");
            recipient2.MergeData.Add("Age", "34");
            recipient2.MergeData.Add("UpSell", "");                    // This will override the Global Merge-Data for this specific Recipient

            var recipient3 = message.To.Add("*****@*****.**"); // The merge-data for this Recipient will be populated with Global Merge-Data

            recipient3.FriendlyName = "Recipient 3";

            // Set other properties as needed
            message.Subject = "Complex BulkSend Example";
            message.From.Set("*****@*****.**", "FromMe");
            message.ReplyTo.Email = "*****@*****.**";

            message.CustomHeaders.Add(new CustomHeader("testMessageHeader", "I am a message header"));

            // Build the Content (Note the %% symbols used to denote the data to be merged)
            var html = new StringBuilder();

            html.AppendLine("<html>");
            html.AppendLine("   <head><title>Complex</title></head>");
            html.AppendLine("   <body>");
            html.AppendLine("       <h1>Merged Data</h1>");
            html.AppendLine("       <p>");
            html.AppendLine("           Motto = <b>%%Motto%%</b> </br>");
            html.AppendLine("           Birthday = <b>%%Birthday%%</b> </br>");
            html.AppendLine("           Age = <b>%%Age%%</b> </br>");
            html.AppendLine("           UpSell = <b>%%UpSell%%</b> </br>");
            html.AppendLine("       </p>");
            html.AppendLine("       </br>");
            html.AppendLine("       <h1>Example of Merge Usage</h1>");
            html.AppendLine("       <p>");
            html.AppendLine("           Our company motto is '<b>%%Motto%%</b>'. </br>");
            html.AppendLine("           Your birthday is <b>%%Birthday%%</b> and you are <b>%%Age%%</b> years old. </br>");
            html.AppendLine("           </br>");
            html.AppendLine("           <b>%%UpSell%%<b>");
            html.AppendLine("       </p>");
            html.AppendLine("   </body>");
            html.AppendLine("</html>");
            message.HtmlBody = html.ToString();

            message.PlainTextBody = Regex.Replace(message.HtmlBody, "<.*?>", string.Empty);

            // Add an Attachment with a custom header
            var attachment = message.Attachments.AddAsync("bus.png", MimeType.PNG, @".\examples\img\bus.png").Result;

            attachment.CustomHeaders.Add(new CustomHeader("Attachment-Header", "I Am A Bus"));
            message.Attachments.Add(attachment);

            // Send the message
            return(client.Send(message));
        }