/// <summary>
        /// If you are sending messages from various points across your code, the
        /// MessageBusFactory will create multiple thread-safe object instances to
        /// efficiently batch transactions, resulting in higher throughput.
        /// </summary>
        void SendExampleEmails()
        {
            var msg1 = new MessageBusEmail {
                ToEmail = "*****@*****.**",
                ToName = "recipient1",
                FromEmail = "*****@*****.**",
                FromName = "Bob",
                Subject = "Test API Email",
                HtmlBody =
                    "<html><body>This is a test message from the MessageBus C# client.</body></html>",
                PlaintextBody = "This is a test message from the MessageBus C# client",
                Tags = new[] { "tag1", "tag2" }
            };
            msg1.CustomHeaders["HEADER"] = "example header";

            var msg2 = new MessageBusEmail {
                ToEmail = "*****@*****.**",
                ToName = "recipient2",
                FromEmail = "*****@*****.**",
                FromName = "Bob",
                Subject = "Test API Email with a different subject",
                HtmlBody =
                    "<html><body>This is a test message from the MessageBus C# client with a different HTML body.</body></html>",
                PlaintextBody =
                    "This is a test message from the MessageBus C# client with a different Plaintext body",
                Tags = new[] { "tag3", "tag4" }
            };
            msg2.CustomHeaders["HEADER"] = "example header";

            var emails = new[] {
              msg1, msg2
            };
            SendMessages(emails);
        }
 /// <summary>
 /// If you are sending messages from various points across your code, the
 /// MessageBusFactory will create multiple thread-safe object instances to
 /// efficiently batch transactions, resulting in higher throughput.
 /// </summary>
 /// <param name="emailAddress">email address</param>
 /// <param name="name">email name</param>
 void SendMessage(string emailAddress, string name)
 {
     var email = new MessageBusEmail {
         ToEmail = emailAddress,
         FromEmail = "*****@*****.**",
         Subject = "Single Message Sample",
         HtmlBody = "<html><body>This message is a test sent by the C# MessageBus client library.</body></html>"
     };
     MessageBus.Send(email);
 }
 public BatchEmailMessage(MessageBusEmail email)
 {
     toEmail = email.ToEmail;
     toName = email.ToName;
     fromEmail = email.FromEmail;
     fromName = email.FromName;
     subject = email.Subject;
     plaintextBody = email.PlaintextBody;
     htmlBody = email.HtmlBody;
     customHeaders = email.CustomHeaders;
     tags = email.Tags;
 }
        public void ThrowsAnErrorIfEmailMergeFieldIfMissing()
        {
            try {

                var email = new MessageBusEmail {
                    ToEmail = "*****@*****.**",
                    Subject = "Test",
                    FromEmail = "*****@*****.**"
                };
                EmailClient.Send(email);
            } catch (MessageBusValidationFailedException) {
                return;
            }
            Assert.Fail("Expected Exception to be thrown");
        }
 public void NoErrorIfACustomMessageIdHeaderIsSupplied()
 {
     try {
         var email = new MessageBusEmail {
             FromEmail = "*****@*****.**",
             ToEmail = "*****@*****.**",
             Subject = "Test",
             PlaintextBody = "Test"
         };
         email.CustomHeaders.Add("message-id", "foo@bar");
         EmailClient.Send(email);
     } catch (MessageBusValidationFailedException) {
         Assert.Fail("Exception should not be thrown");
         return;
     }
     return;
 }
        private void Validate(MessageBusEmail email)
        {
            if (SkipValidation) return;
            string msg = "";

            if (String.IsNullOrEmpty(ApiKey)) {
                msg = "ApiKey is required";
            }

            if (String.IsNullOrEmpty(email.FromEmail)) {
                msg = "From Email is required";
            }

            if (String.IsNullOrEmpty(email.Subject)) {
                msg = "Subject is required";
            }

            if (String.IsNullOrEmpty(email.ToEmail)) {
                msg = "ToEmail is required";
            }

            if (String.IsNullOrEmpty(email.PlaintextBody) && String.IsNullOrEmpty(email.HtmlBody)) {
                msg = "Either HtmlBody or PlaintextBody is required";
            }

            if (msg.Length > 0) {
                Logger.error(msg);
                throw new MessageBusValidationFailedException(msg);
            }
        }
 public bool Send(MessageBusEmail email)
 {
     Validate(email);
     return Send(new BatchEmailMessage(email));
 }