예제 #1
0
        public void TestThree()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();

            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());

            emailmessage.Subject = "Something has come up";

            emailmessage.TextPart = new TextAttachment("I regret that something has " +
                                                       "come up unexpectedly,\r\n" +
                                                       "and I must postpone our meeting.\r\n\r\n" +
                                                       "Please read the 20 pages of my thoughts on this in the attached\r\n" +
                                                       "PDF file.\r\n\r\n-Marcel");

            emailmessage.HtmlPart = new HtmlAttachment("<p>I regret that something " +
                                                       "has come up unexpectedly,\r\n" +
                                                       "and I must postpone our meeting.</p>\r\n" +
                                                       "<p>Please read the 20 pages of my thoughts on this in the attached\r\n" +
                                                       "PDF file.</p>\r\n<p>-Marcel</p>");

            FileAttachment fileattachment = new FileAttachment(new FileInfo(@"..\..\TestFiles\grover.jpg"));

            fileattachment.ContentType = "image/jpeg";

            emailmessage.AddMixedAttachment(fileattachment);

            emailmessage.Send(TestAddressHelper.GetSmtpServer());
        }
예제 #2
0
        public void TestTwo()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();

            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());

            emailmessage.Subject = "A photo of hawthornes";

            emailmessage.TextPart = new TextAttachment("This photo requires a better email reader.");
            emailmessage.HtmlPart = new HtmlAttachment("<html><body>" +
                                                       "<p>Note to self: look at this photo again in 30 years.</p>" +
                                                       "<p><img src=\"cid:hawthornes\" alt=\"Hawthorne bush\"/></p>" +
                                                       "<p>-Marcel</p>");

            FileInfo relatedfileinfo = new FileInfo(@"..\..\TestFiles\grover.jpg");

            FileAttachment relatedfileattachment = new FileAttachment(relatedfileinfo, "hawthornes");

            relatedfileattachment.ContentType = "image/jpeg";

            emailmessage.AddRelatedAttachment(relatedfileattachment);

            SmtpServer smtpserver = TestAddressHelper.GetSmtpServer();

            emailmessage.Send(smtpserver);
            //Assert.IsNull(smtpserver.GetSmtpConversation());
        }
예제 #3
0
        public void TestOne()
        {
            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();

            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());

            emailmessage.Subject = "Missed you";

            emailmessage.TextPart = new TextAttachment("Just checking where " +
                                                       "you were last night.\r\nSend me a note!\r\n\r\n-Charles");

            emailmessage.HtmlPart = new HtmlAttachment("<html><body>" +
                                                       "<p>Just checking up on where you were last night.</p>\r\n" +
                                                       "<p>Send me a note!</p>\r\n\r\n" +
                                                       "<p>-Charles</p></body></html>");

            SmtpServer smtpserver = TestAddressHelper.GetSmtpServer();

            //smtpserver.CaptureSmtpConversation=true;

            try
            {
                emailmessage.Send(smtpserver);
            }
            finally
            {
                //log.Debug(smtpserver.GetSmtpConversation());
                //Assert.IsNotNull(smtpserver.GetSmtpConversation());
                //smtpserver.CaptureSmtpConversation=false;
            }
        }
예제 #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);
        }
예제 #5
0
        public void TestLargerBinaryFileFromStream()
        {
            String filename = "casingTheJoint.jpg";

            EmailMessage emailmessage = new EmailMessage();

            emailmessage.FromAddress = TestAddressHelper.GetFromAddress();

            emailmessage.AddToAddress(TestAddressHelper.GetToAddress());

            emailmessage.Subject = "Here's your file";

            emailmessage.TextPart = new TextAttachment("This a zip file.");

            emailmessage.HtmlPart = new HtmlAttachment("<html><body>" +
                                                       "<p>This a zip file.</p>\r\n");

            FileInfo   fileinfo   = new FileInfo(@"..\..\TestFiles\" + filename);
            FileStream filestream = fileinfo.OpenRead();

            MemoryStream stream = new MemoryStream();

            StreamWriter sw = new StreamWriter(stream);

            sw.Flush();

            //BinaryReader br=new BinaryReader(stream);

            BinaryReader br = new BinaryReader(filestream);

            byte[] bytes = br.ReadBytes((int)fileinfo.Length);
            br.Close();

            FileAttachment fileAttachment = new FileAttachment(bytes);

            //fileAttachment.ContentType
            fileAttachment.FileName    = filename;
            fileAttachment.ContentType = "application/zip";
            emailmessage.AddMixedAttachment(fileAttachment);

            emailmessage.Send(TestAddressHelper.GetSmtpServer());
        }
예제 #6
0
        public void TestDocFile()
        {
            EmailMessage mail = new EmailMessage();

            FileInfo fileinfo = new FileInfo(@"..\..\TestFiles\TestWord.doc");

            Assert.IsTrue(fileinfo.Exists);

            FileAttachment fileAttachment = new FileAttachment(fileinfo);

            fileAttachment.ContentType = "application/msword";

            //EmailAddress emailAddress = new EmailAddress(emailAddressParam);
            mail.TextPart = new TextAttachment("Here is your file");
            mail.AddMixedAttachment(fileAttachment);

            mail.FromAddress = TestAddressHelper.GetFromAddress();
            mail.AddToAddress("*****@*****.**");

            SmtpServer smtpServer = TestAddressHelper.GetSmtpServer();

            mail.Send(smtpServer);
        }
예제 #7
0
 public void SetUp()
 {
     _smtpserver = TestAddressHelper.GetSmtpServer();
 }