Karl Gjertsen

Architect, Developer, Speaker, Bad Golfer,
Raygun brand ambassador and creator of Infiniforms

Email

Saving an email to SQL Server with Mail4Net

There are a number of reasons why you might want to save your email to a SQL Server database. Maybe you want to be able to resend the message if it doesn’t arrive. A common reason is to have the sending process performed by a dedicated service, such as MailSender, which will soon be available to download from the Mail4Net…

Inversion of control in Mail4Net

Inversion of Control All of the Mail4Net client classes implement a common interface, ISmtpClient. This allows you to use the inversion of control pattern with the Mail4Net clients. To demonstrate using IoC with Mail4Net, I have created a sample class called MailCreator class, which has a SendEmail method that takes an email address and then sends an email to that…

Unit testing email code with Mail4Net

When it comes to unit testing your code, Mail4Net provides a great way to test your email sending code. In my previous article, I showed sending an email with Mail4Net. If you are new to Mail4Net, then I would suggest you start with this article. Using the fake client The fake client stores emails that have been sent and they…

Sending an email with Mail4Net

Mail4Net is a .NET library for creating, managing and sending emails. Sending an email Typically, you create a MailMessage class, populate it and then send it to a SMTP server, using Microsoft’s System.Net.Mail.SmtpClient class: private void SendEmail() { // Create mail message. var message = new System.Net.Mail.MailMessage(); message.To.Add(“someone@mydomain.com”); message.From = new MailAddress(“me@mydomain.com”); message.Subject = “Hello World”; message.Body = “Here is…

Mail4Net

I have recently been working on Mail4Net, a very interesting piece of software for .NET developers. It includes software to create and manage email templates and a .NET class library for creating email messages from saved templates, populating data into the templates and then sending the populated email. You can also choose to save the email to a folder or…