ExampleTests.cs :  » Email » DotNetOpenMail » DotNetOpenMailTests » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Email » DotNetOpenMail 
DotNetOpenMail » DotNetOpenMailTests » ExampleTests.cs
using System;
using System.IO;
using DotNetOpenMail; // change to tested dir

using NUnit.Framework;
using log4net;

namespace DotNetOpenMailTests{

  [TestFixture]
  public class ExampleTests {

    private static readonly ILog log = LogManager.GetLogger(typeof(ExampleTests));

    public ExampleTests() {
    }

    [SetUp]
    public void SetUp() {}

    [TearDown]
    public void TearDown() {}

    [Test]
    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;  
      }
    }
    [Test]
    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());
    }

    [Test]
    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());
  
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.