コード例 #1
0
        /// <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);
        }
コード例 #2
0
 /// <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);
 }
コード例 #3
0
 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;
 }
コード例 #4
0
        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");
        }
コード例 #5
0
 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;
 }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
 public bool Send(MessageBusEmail email)
 {
     Validate(email);
     return Send(new BatchEmailMessage(email));
 }