Esempio n. 1
0
 public void ToAttachmentData_Text()
 {
     var attachment = new TextAttachment("name", MimeTypes.PlainText, "content");
     AttachmentData attachmentData = attachment.ToAttachmentData();
     Assert.AreEqual("name", attachmentData.Name);
     Assert.AreEqual(MimeTypes.PlainText, attachmentData.ContentType);
     Assert.AreEqual("content", attachmentData.GetText());
     Assert.AreEqual(AttachmentContentDisposition.Inline, attachmentData.ContentDisposition);
     Assert.AreEqual(AttachmentType.Text, attachmentData.Type);
 }
Esempio n. 2
0
        public void ToAttachmentData_Text()
        {
            var            attachment     = new TextAttachment("name", MimeTypes.PlainText, "content");
            AttachmentData attachmentData = attachment.ToAttachmentData();

            Assert.AreEqual("name", attachmentData.Name);
            Assert.AreEqual(MimeTypes.PlainText, attachmentData.ContentType);
            Assert.AreEqual("content", attachmentData.GetText());
            Assert.AreEqual(AttachmentContentDisposition.Inline, attachmentData.ContentDisposition);
            Assert.AreEqual(AttachmentType.Text, attachmentData.Type);
        }
        public void TextAttachment()
        {
            var content = new TextAttachment
            {
                Name    = "Test",
                Content = "Content"
            };

            var factory   = new MailAttachmentFactory();
            var candidate = factory.CreateAttachement(content);

            Assert.IsNotNull(candidate);
            Assert.AreEqual("Test", candidate.Name);
        }
Esempio n. 4
0
        public void TestWindows1251()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();
            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());

            emailmessage.Subject       = "ошибочка?";
            emailmessage.HeaderCharSet = System.Text.Encoding.GetEncoding("windows-1251");

            TextAttachment ta = new TextAttachment("\r\nнесколько строк по русски");

            ta.CharSet            = System.Text.Encoding.GetEncoding("windows-1251");
            emailmessage.TextPart = ta;
            emailmessage.Send(TestAddressHelper.GetSmtpServer());
            Assert.IsTrue(emailmessage.ToDataString().IndexOf("Subject: =?windows-1251") > 0, "Missing windows-1251 in subject");
            Assert.IsTrue(emailmessage.ToDataString().IndexOf("koi8-r") < 0);
        }
        public void Send()
        {
            var attachmentFactory = new Mock <IMailAttachmentFactory>();
            var notifier          = new Mock <IMessageDispatchNotifier>();

            var dispatcher = new MailMessageDispatcher(attachmentFactory.Object, notifier.Object);

            var source = new TextAttachment
            {
                Name    = "Text",
                Content = "Content"
            };

            var attachment = new Attachment(new MemoryStream(Encoding.ASCII.GetBytes("Content")), "Test");

            attachmentFactory.Setup(x => x.CreateAttachement(It.IsAny <IAttachment>())).Returns(attachment);

            var message = new Message
            {
                From          = "*****@*****.**",
                FromName      = "From",
                BounceAddress = "*****@*****.**",
                Subject       = "Subject",
                Text          = "Text",
                Html          = "Html",
            };

            message.ToAddress.Add("*****@*****.**");
            message.Cc.Add("*****@*****.**");
            message.Bcc.Add("*****@*****.**");
            message.Headers["X-Path"] = "xpath";
            message.Attachments.Add(source);

            dispatcher.Send(message);

            Assert.AreEqual(1, smtpServer.ReceivedEmailCount, "Count differs");
            notifier.Verify(x => x.Notify(It.IsAny <IMessage>(), true, null));

            var candidate = smtpServer.ReceivedEmail.First();

            Assert.AreEqual("Subject", candidate.Subject, "Subject differs");
        }