Ejemplo n.º 1
0
        /// <summary>
        ///     This feature allows you to create a message template, and specify different replacement
        ///     strings for each specific recipient
        /// </summary>
        public void AddSubstitutionValues()
        {
            //create a new message object
            var message = new SendGrid();

            //set the message recipients
            foreach (var recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Text = "Hi %name%! Pleased to meet you!";

            //set the message subject
            message.Subject = "Testing Substitution Values";

            //This replacement key must exist in the message body
            var replacementKey = "%name%";

            //There should be one value for each recipient in the To list
            var substitutionValues = new List<String> {"Mr Foo", "Mrs Raz"};

            message.AddSubstitution(replacementKey, substitutionValues);

            //create an instance of the SMTP transport mechanism
            var transportInstance = new Web(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }
Ejemplo n.º 2
0
        public void EnableBypassListManagement()
        {
            var header = new Header();
            var sendgrid = new SendGrid(header);

            sendgrid.EnableBypassListManagement();

            var json = header.JsonString();
            Assert.AreEqual("{\"filters\" : {\"bypass_list_management\" : {\"settings\" : {\"enable\" : \"1\"}}}}", json);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     This feature adds key value identifiers to be sent back as arguments over the event api for
        ///     various events
        /// </summary>
        public void AddUniqueIdentifiers()
        {
            //create a new message object
            var message = new SendGrid();

            //set the message recipients
            foreach (var recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Text = "Hello World";

            //set the message subject
            message.Subject = "Testing Unique Identifiers";

            var identifiers = new Dictionary<String, String>();
            identifiers["customer"] = "someone";
            identifiers["location"] = "somewhere";

            message.AddUniqueArgs(identifiers);

            //create an instance of the SMTP transport mechanism
            var transportInstance = new Web(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     This feature tags the message with a specific tracking category, which will have aggregated stats
        ///     viewable from your SendGrid account page.
        /// </summary>
        public void SetCategory()
        {
            //create a new message object
            var message = new SendGrid();

            //set the message recipients
            foreach (var recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            message.Text = "Hello World";

            //set the message subject
            message.Subject = "Testing Categories";

            var category = "vipCustomers";

            message.SetCategory(category);

            //create an instance of the SMTP transport mechanism
            var transportInstance = new Web(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     This feature wraps an HTML template around your email content.
        ///     This can be useful for sending out newsletters and/or other HTML formatted messages.
        ///     hhttp://docs.sendgrid.com/documentation/apps/email-templates/
        /// </summary>
        public void EnableBypassListManagementEmail()
        {
            //create a new message object
            var message = new SendGrid();

            //set the message recipients
            foreach (var recipient in _to)
            {
                message.AddTo(recipient);
            }

            //set the sender
            message.From = new MailAddress(_from);

            //set the message body
            var timestamp = DateTime.Now.ToString("HH:mm:ss tt");
            message.Html = "<p style='color:red';>Hello World</p>";
            message.Html += "<p>Sent At : " + timestamp + "</p>";

            message.Text = "Hello World plain text";

            //set the message subject
            message.Subject = "Hello World Bypass List Management Test";

            //create an instance of the Web transport mechanism
            var transportInstance = new Web(new NetworkCredential(_username, _password));

            //enable bypass list management
            message.EnableBypassListManagement();

            //send the mail
            transportInstance.Deliver(message);
        }