コード例 #1
0
        public void ArgumentsToSendTakePriorityOverHeader()
        {
            // Arrange
            var message = new MailMessage();
            var headers = new[]
            {
                "from:[email protected]",
                "cc:[email protected]",
                "priority:low"
            };

            // Act
            WebMail.SetPropertiesOnMessage(
                message,
                null,
                null,
                null,
                "*****@*****.**",
                "*****@*****.**",
                null,
                null,
                null,
                null,
                MailPriority.High,
                null,
                false,
                headers
                );

            // Assert
            Assert.Equal("*****@*****.**", message.From.Address);
            Assert.Equal("*****@*****.**", message.CC.First().Address);
            Assert.Equal("*****@*****.**", message.CC.Last().Address);
            Assert.Equal(MailPriority.High, message.Priority);
        }
コード例 #2
0
        public void PropertiesDuplicatedAcrossHeaderAndArgumentDoesNotThrow()
        {
            // Arrange
            var message = new MailMessage();
            var headers = new[] { "to:[email protected]" };

            // Act
            WebMail.SetPropertiesOnMessage(
                message,
                "*****@*****.**",
                null,
                null,
                "*****@*****.**",
                null,
                null,
                null,
                null,
                null,
                MailPriority.Normal,
                null,
                false,
                headers
                );

            // Assert
            Assert.Equal(2, message.To.Count);
            Assert.Equal("*****@*****.**", message.To.First().Address);
            Assert.Equal("*****@*****.**", message.To.Last().Address);
        }
コード例 #3
0
ファイル: WebMailTest.cs プロジェクト: yersans/AspNetWebStack
        public void SetPropertiesOnMessageTest_SetsAllInfoCorrectlyOnMailMessageTest()
        {
            // Arrange
            MailMessage message         = new MailMessage();
            string      to              = "*****@*****.**";
            string      subject         = "subject1";
            string      body            = "body1";
            string      from            = FromAddress;
            string      cc              = "*****@*****.**";
            string      attachmentName  = "NETLogo.png";
            string      bcc             = "*****@*****.**";
            string      replyTo         = "[email protected],[email protected]";
            string      contentEncoding = "utf-8";
            string      headerEncoding  = "utf-16";
            var         priority        = MailPriority.Low;

            // Act
            string fileToAttach = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            try
            {
                TestFile.Create(attachmentName).Save(fileToAttach);
                bool isBodyHtml        = true;
                var  additionalHeaders = new[] { "header1:value1" };
                WebMail.SetPropertiesOnMessage(message, to, subject, body, from, cc, bcc, replyTo, contentEncoding, headerEncoding, priority, new[] { fileToAttach }, isBodyHtml, additionalHeaders);

                // Assert
                Assert.Equal(body, message.Body);
                Assert.Equal(subject, message.Subject);
                Assert.Equal(to, message.To[0].Address);
                Assert.Equal(cc, message.CC[0].Address);
                Assert.Equal(from, message.From.Address);
                Assert.Equal(bcc, message.Bcc[0].Address);
                Assert.Equal("*****@*****.**", message.ReplyToList[0].Address);
                Assert.Equal("*****@*****.**", message.ReplyToList[1].Address);
                Assert.Equal(MailPriority.Low, message.Priority);
                Assert.Equal(Encoding.UTF8, message.BodyEncoding);
                Assert.Equal(Encoding.Unicode, message.HeadersEncoding);

                Assert.True(message.Headers.AllKeys.Contains("header1"));
                Assert.True(message.Attachments.Count == 1);
            }
            finally
            {
                try
                {
                    File.Delete(fileToAttach);
                }
                catch (IOException)
                {
                } // Try our best to clean up after ourselves
            }
        }