The central class to the email package. It can be configured to send emails.
        /// <summary>
        /// Send a test email based on the configuration of an Umbraco email node. This email is sent exclusively to the specified recipient parameter (CC and BCC are ignored)
        /// </summary>
        /// <param name="umbracoEmailNodeId">The ID of the configured Umbraco email node</param>
        /// <param name="recipients">The emailaddress to receive the test email</param>
        /// <param name="values">List of tags render in the email</param>
        /// <returns>The ID of the logged email</returns>
        public static int SendUmbracoTestEmail(int umbracoEmailNodeId, IEnumerable<MailAddress> recipients, List<EmailTag> values)
        {
            var m = new Email(umbracoEmailNodeId, values);

            m.To.Clear();
            foreach (var recipient in recipients)
                m.To.Add(recipient);
            m.CC.Clear();
            m.BCC.Clear();
            return m.SendEmail();
        }
        public static void DownloadEmail(int logmailID)
        {
            var logMail = LogEmail.Get(logmailID);

            var m = new Email();
            m.To.Add(new MailAddress(logMail.to));
            m.From = new MailAddress(logMail.from);
            if (!String.IsNullOrEmpty(logMail.replyTo))
                m.ReplyToList.Add(new MailAddress(logMail.replyTo));
            if (!String.IsNullOrEmpty(logMail.cc))
                m.CC.Add(new MailAddress(logMail.cc));
            if (!String.IsNullOrEmpty(logMail.bcc))
                m.BCC.Add(new MailAddress(logMail.bcc));
            if (!String.IsNullOrEmpty(logMail.host))
                m.SmtpHost = logMail.host;
            if (!String.IsNullOrEmpty(logMail.userID))
                m.SetSmtpCredentials(logMail.userID, null); // Dit is natuurlijk knudde want zonder het wachtwoord kom je niet ver
            m.Subject = logMail.subject;
            m.Body = logMail.body;
            m.EmailId = logMail.emailID;
            m.AlternativeView = logMail.alternativeView;
            if (!String.IsNullOrEmpty(logMail.attachment))
                foreach (String attachment in logMail.attachment.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    if (!string.IsNullOrEmpty(attachment)) // redundant
                    {
                        // Is the string actually an integer?
                        int tmp;
                        if (attachment.All(c => Char.IsDigit(c)))
                        {
                            if (int.TryParse(attachment, out tmp))
                            {
                                // Ah, that's convienent since it's an Umbraco Media Node Id. Try to get the media file from Umbraco
                                string filename = Helper.GetUmbracoMediaFile(tmp, true);
                                if (!String.IsNullOrEmpty(filename))
                                    m.Attachments.Add(new Attachment(filename));
                            }
                        }
                        else
                            // Fysical path on the harddisk
                            m.Attachments.Add(new Attachment(attachment));
                    }

            m._mail.Attachments.Clear();
            foreach (var a in m.Attachments)
            {
                if (a.Stream != null)
                    // Use the supplied stream
                    m._mail.Attachments.Add(new System.Net.Mail.Attachment(a.Stream, a.FileName));
                else
                    // Find the file on the harddisk
                    m._mail.Attachments.Add(new System.Net.Mail.Attachment(a.FileDirectory + a.FileName));
            }

            // Filename in the beowser as "nodename - logId - email"
            string downloadFilename = new Node(m.EmailId).Name + " - " + logmailID.ToString();

            if (m.To != null && m.To.Count > 0)
                downloadFilename += " - " + m.To[0].Address;

            downloadFilename = Helper.SanitizeFilename(downloadFilename);
            Helper.SendMailMessageToBrowser(m._mail, downloadFilename);
        }
        /// <summary>
        /// Resend any email that has previously been sent and logged. The email to resend is based on the email log ID, so only emails present in the log table can be resent.
        /// </summary>
        /// <param name="logmailID">The email log ID</param>
        /// <param name="recipientEmail">(optioneel) The alternative recipient of the email that will be resent. If left null or empty, the original recipient's emailaddress will be used</param>
        /// <param name="includeCC">Should the email also be sent to the original CC recipients?</param>
        /// <param name="includeBCC">Should the email also be sent to the original CC recipients?</param>
        /// <returns>The log ID of the email that was sent</returns>
        public static int ReSendEmail(int logmailID, string recipientEmail = null, bool includeCC = false, bool includeBCC = false)
        {
            var logMail = LogEmail.Get(logmailID);

            var m = new Email();
            m.To.Add(new MailAddress(recipientEmail ?? logMail.to));
            m.From = new MailAddress(logMail.from);
            if (!String.IsNullOrEmpty(logMail.replyTo))
                m.ReplyToList.Add(new MailAddress(logMail.replyTo));
            if (!String.IsNullOrEmpty(logMail.cc))
                m.CC.Add(new MailAddress(logMail.cc));
            if (!String.IsNullOrEmpty(logMail.bcc))
                m.BCC.Add(new MailAddress(logMail.bcc));
            if (!String.IsNullOrEmpty(logMail.host))
                m.SmtpHost = logMail.host;
            if (!String.IsNullOrEmpty(logMail.userID))
                m.SetSmtpCredentials(logMail.userID, null); // Dit is natuurlijk knudde want zonder het wachtwoord kom je niet ver
            m.Subject = logMail.subject;
            m.Body = logMail.body;
            m.EmailId = logMail.emailID;
            m.AlternativeView = logMail.alternativeView;
            if (!String.IsNullOrEmpty(logMail.attachment))
                foreach (String attachment in logMail.attachment.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    if (!string.IsNullOrEmpty(attachment)) // redundant
                    {
                        // Is het toevallig een Umbraco Media Node Id?
                        int tmp;
                        if (attachment.All(c => Char.IsDigit(c)))
                        {
                            if (int.TryParse(attachment, out tmp))
                            {
                                // Ah, dat is makkelijk, gewoon het bestand uit Umbraco vissen
                                string filename = Helper.GetUmbracoMediaFile(tmp, true);
                                if (!String.IsNullOrEmpty(filename))
                                    m.Attachments.Add(new Attachment(filename));
                            }
                        }
                        else
                            // Fysiek pad op de schijf
                            m.Attachments.Add(new Attachment(attachment));
                    }
            return m.SendEmail();
        }
        /// <summary>
        /// Send a email based on the configuration of an Umbraco email node.
        /// </summary>
        /// <param name="umbracoEmailNodeId">The ID of the configured Umbraco email node</param>
        /// <param name="recipient"> The recipient of the email. The recipient may also be specified on the Umbraco email node</param>
        /// <param name="values">List of tags render in the email</param>
        /// <param name="attachments">The list of attachments that are sent with the email</param>
        /// <returns>The ID of the logged email</returns>
        public static Email CreateUmbracoEmail(int umbracoEmailNodeId, List<EmailTag> values, IEnumerable<Attachment> attachments)
        {
            // Validate the ID
            if (umbracoEmailNodeId == 0)
                throw new ArgumentException("Invalid Umbraco Node Id (must be >= 1000)", "mailNodeID");

            // Validate e-mail node
            var nMail = new Node(umbracoEmailNodeId);
            if (nMail == null || nMail.Id == 0)
                throw new Exception("The specified Umbraco Node with id '" + umbracoEmailNodeId.ToString() + "' does not exist.");

            // Create an e-mail object based on the settings in the specified Umbraco email node
            var m = new Email(umbracoEmailNodeId, values);

            if (attachments != null)
                m.Attachments.AddRange(attachments);

            return m;
        }