9

I've been writing a bunch of email code lately and it occurred to me that it'd be pretty cool if there was a library that allowed you to fluently create an email in c#.

I had a quick look around but couldn't find anything so was wondering if anyone knew if there was a fluent email library that already existed for c#?

lomaxx
  • 113,627
  • 57
  • 144
  • 179
  • 2
    what do you mean by fluent? is System.Net.Mail too difficult to use for you? Of course you can create your own class which wraps it and makes it easier and simpler to use it... – Davide Piras Feb 17 '11 at 12:14
  • 4
    Think he wants something like: Send(message).To(recipient).And(recipient2).From(sender).Now(); – Phill Feb 17 '11 at 12:20

4 Answers4

6

I ended up finding this on GitHub which does what I want pretty nicely

https://github.com/dkarzon/FluentEmail

Also has the added bonus of allowing templates which can be used like so:

var email = Email
            .From("john@email.com")
            .To("bob@email.com", "bob")
            .Subject("hows it going bob")
            .UsingTemplate(@"C:\Emailer\TransactionTemplate.htm")
            .Replace("<%CurrentDate%>", DateTime.Now.ToShortDateString())
            .Replace("<%FullName%>", fullName)
            .Replace("<%SaleDate%>", saleDate)
lomaxx
  • 113,627
  • 57
  • 144
  • 179
3

You can check out my Mail.dll email component:

Mail.Html(@"Html with an image: <img src=""cid:lena="""" />")
  .AddVisual(@"c:\lena.jpeg").SetContentId("lena")
  .AddAttachment(@"c:\tmp.doc").SetFileName("document.doc")
  .To("to@mail.com")
  .From("from@mail.com")
  .Subject("Subject")
  .SignWith(new X509Certificate2("SignCertificate.pfx", ""))
  .EncryptWith(new X509Certificate2("EncryptCertificate.pfx", ""))
  .EncryptWith(new X509Certificate2("BobsCertificate.pfx", ""))
  .UsingNewSmtp()
  .Server("smtp.example.com")
  .Send();

It's not free however and fluent interface is just syntactic sugar.

Pawel Lesnikowski
  • 6,264
  • 4
  • 38
  • 42
1

My Class :D http://www.mediafire.com/download/m7oua8gf4ject8m/Mail.cs

to use :

using Mailling;

    MailController m = new MailController("username", "password");

    private void Form1_Load(object sender, EventArgs e)
    {
        //Gett Mails
        List<Mail> mails = m.GetAllMails();
        foreach (Mail item in mails)
        {
            MessageBox.Show("From : "+item.From+"\n"+"Title: "+item.Title+"\n"+"Summary : "+item.Summary);
        }

        //SendMail
        m.SendMail("username", "password", "title", "summary");

    }
okidoki
  • 11
  • 1
-2

You can also check out this one. Fully featured and easy to use. Offers a fantastic way to build up templated emails.

http://www.avantprime.com/products/view-product/8/fluent-mail