public static void SetBodyEncoding(this SendEMailCommand command, Encoding encoding)
        {
            Guard.AgainstNull(command, "command");
            Guard.AgainstNull(encoding, "encoding");

            command.BodyEncoding = encoding.HeaderName;
        }
        public static MailPriority GetMailPriority(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            try
            {
                return((MailPriority)Enum.Parse(typeof(MailPriority), command.Priority));
            }
            catch (Exception)
            {
                return(MailPriority.Normal);
            }
        }
        public string AddAttachment(SendEMailCommand command, string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(string.Format(EMailResources.AttachmentFileNotFound, path));
            }

            var name       = Guid.NewGuid().ToString("n");
            var file       = string.Format("{0}{1}", name, Path.GetExtension(path));
            var targetPath = Path.Combine(_configuration.AttachmentFolder, file);

            try
            {
                File.Copy(path, targetPath, true);
            }
            catch (Exception ex)
            {
                throw new EMailException(string.Format(EMailResources.AttachmentFileException, path, ex.AllMessages()));
            }

            if (Log.IsTraceEnabled)
            {
                var log = new StringBuilder();

                log.AppendFormat("Date created\t{0}", DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"));
                log.AppendLine();
                log.AppendFormat("Source file path:\t{0}", path);
                log.AppendLine();
                log.AppendFormat("Source machine\t{0}", Environment.MachineName);
                log.AppendLine();
                log.AppendFormat("Source identity\t{0}", string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName));
                log.AppendLine();

                var logPath = Path.Combine(_configuration.AttachmentFolder, string.Format("{0}.log", name));

                try
                {
                    File.WriteAllText(logPath, log.ToString());
                }
                catch (Exception ex)
                {
                    _log.Error(string.Format(EMailResources.LogFileException, logPath, ex.AllMessages()));
                }
            }

            command.Attachments.Add(file);

            return(file);
        }
        public static Encoding GetSubjectEncoding(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            if (NullEncoding(command.SubjectEncoding))
            {
                return(null);
            }

            try
            {
                return(Encoding.GetEncoding(command.SubjectEncoding));
            }
            catch
            {
                return(null);
            }
        }
        public static bool HasSubjectEncoding(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            return(command.GetSubjectEncoding() != null);
        }
        public static bool HasBodyEncoding(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            return(command.BodyEncoding != null);
        }
        public static void SetMailPriority(this SendEMailCommand command, MailPriority priority)
        {
            Guard.AgainstNull(command, "command");

            command.Priority = priority.ToString();
        }