public void Test_DisablingFooter()
        {
            var mail = BasicMailBuilder
                .DisableFooter()
                .Build();

            var message = new SendGridMessage();
            message.DisableFooter();
            Assert.IsFalse(string.IsNullOrEmpty(message.Header.JsonString()));
            Assert.AreEqual(message.Header.JsonString(), mail.Header.JsonString());
        }
示例#2
0
 public MailBuilder DisableFooter()
 {
     sendgrid.DisableFooter();
     return(this);
 }
        public static void SendEmailViaSendGrid(string to, string from, string subject, string htmlBody, MailType type, string textBody, string[] multipleTo = null)
        {
            try
            {
                //var message = SendGrid.GenerateInstance();
                var message = new SendGridMessage();
                if (String.IsNullOrEmpty(to))
                    message.AddTo(multipleTo);
                else
                    message.AddTo(to);

                //if (multipleTo != null)
                //    message.AddTo(multipleTo);
                //else
                //    message.AddTo(to);

                message.From = new System.Net.Mail.MailAddress(from);
                message.Subject = subject;
                if (type == MailType.TextOnly)
                    message.Text = textBody.Replace(@"\r\n", Environment.NewLine);
                else if (type == MailType.HtmlOnly)
                    message.Html = htmlBody;
                else
                {
                    message.Html = htmlBody;
                    message.Text = textBody;
                }

                //Dictionary<string, string> collection = new Dictionary<string, string>();
                //collection.Add("header", "header");
                //message.Headers = collection;

                message.EnableOpenTracking();
                message.EnableClickTracking();
                message.DisableUnsubscribe();
                message.DisableFooter();
                message.EnableBypassListManagement();
                //var transportInstance = SMTP.GenerateInstance(new System.Net.NetworkCredential(SendGridUsername, SendGridPassword), SendGridSmtpHost, SendGridSmtpPort);
                var transportInstance = new Web(new System.Net.NetworkCredential(SendGridUsername, SendGridPassword));
                transportInstance.Deliver(message);
                if (String.IsNullOrEmpty(to))
                    Console.WriteLine("SendGrid: Email was sent successfully to " + multipleTo);
                else
                    Console.WriteLine("SendGrid: Email was sent successfully to " + to);
            }
            catch (Exception)
            {
                if (String.IsNullOrEmpty(to))
                    Console.WriteLine("SendGrid: Unable to send email to " + multipleTo);
                else
                    Console.WriteLine("SendGrid: Unable to send email to " + to);
                throw;
            }
        }
        public void DisableFooter()
        {
            var header = new Header();
            var sendgrid = new SendGridMessage(header);

            sendgrid.DisableFooter();

            var json = header.JsonString();
            Assert.AreEqual("{\"filters\" : {\"footer\" : {\"settings\" : {\"enable\" : \"0\"}}}}", json);
        }