Beispiel #1
0
        private EmailMessage GetTestHtmlAndTextMessage()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());
            emailmessage.Subject  = "EmailMessageTests Test HTML and Text";
            emailmessage.TextPart = new TextAttachment("This\r\nis the\r\ntext\r\npart.");
            emailmessage.HtmlPart = new HtmlAttachment("<html><body>This<br>\r\nis the<br>\r\n<strong>HTML</strong><br>\r\npart.</body></html>");

            emailmessage.AddCustomHeader("X-MyHeader1", "my header number one");
            emailmessage.AddCustomHeader("X-MyHeader2", "my header number two");

            return(emailmessage);
        }
        public void TestFor8BitHeader()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.HeaderCharSet  = System.Text.ASCIIEncoding.ASCII;
            emailmessage.HeaderEncoding = DotNetOpenMail.Encoding.EncodingType.EightBit;

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());
            emailmessage.Subject           = "EmailMessageTests Test HTML and Text";
            emailmessage.TextPart          = new TextAttachment("This\r\nis the\r\ntext\r\npart.");
            emailmessage.TextPart.CharSet  = System.Text.ASCIIEncoding.ASCII;
            emailmessage.TextPart.Encoding = DotNetOpenMail.Encoding.EncodingType.EightBit;

            emailmessage.HtmlPart          = new HtmlAttachment("<html><body>This<br>\r\nis the<br>\r\n<strong>HTML</strong><br>\r\npart.</body></html>");
            emailmessage.HtmlPart.CharSet  = System.Text.ASCIIEncoding.ASCII;
            emailmessage.HtmlPart.Encoding = DotNetOpenMail.Encoding.EncodingType.EightBit;

            //emailmessage.Send(_smtpserver);

            String       content = emailmessage.ToDataString();
            StringReader sr      = new StringReader(content);

            log.Debug(content);

            int    i    = 0;
            String line = null;

            String expectedToAddress = TestAddressHelper.GetToAddress().Name + " <" + TestAddressHelper.GetToAddress().Email + ">";
            int    has8Bit           = 0;
            int    hasUSASCII        = 0;

            while ((line = sr.ReadLine()) != null)
            {
                i++;
                if (line.IndexOf("Content-Transfer-Encoding: 8bit") == 0)
                {
                    has8Bit++;
                }
                if (line.IndexOf("charset=\"us-ascii\"") > 0)
                {
                    hasUSASCII++;
                }
                log.Debug("Line " + i + ": " + line);
            }
            Assert.AreEqual(2, has8Bit, "Not enough 8bit lines");
            Assert.AreEqual(2, hasUSASCII, "Not enough us-ascii lines");
        }