コード例 #1
0
        public static void SetBodyEncoding(this SendEMailCommand command, Encoding encoding)
        {
            Guard.AgainstNull(command, "command");
            Guard.AgainstNull(encoding, "encoding");

            command.BodyEncoding = encoding.HeaderName;
        }
コード例 #2
0
        public static Encoding GetSubjectEncoding(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            if (string.IsNullOrEmpty(command.SubjectEncoding)
                ||
                command.SubjectEncoding.Equals("default", StringComparison.InvariantCultureIgnoreCase)
                ||
                command.SubjectEncoding.Equals("none", StringComparison.InvariantCultureIgnoreCase)
                ||
                command.SubjectEncoding.Equals("empty", StringComparison.InvariantCultureIgnoreCase)
                ||
                command.SubjectEncoding.Equals("unknown", StringComparison.InvariantCultureIgnoreCase))
            {
                return(null);
            }

            try
            {
                return(Encoding.GetEncoding(command.SubjectEncoding));
            }
            catch
            {
                return(null);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public string AddAttachment(SendEMailCommand command, string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(string.Format("File '{0}' does not exist.  Could not add e-mail attachment.", 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("File '{0}' not added as attachment.  Exception reported: {1}", path, ex.CompactMessages()));
            }

            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();

            File.WriteAllText(Path.Combine(configuration.AttachmentFolder, string.Format("{0}.log", name)), log.ToString());

            command.Attachments.Add(file);

            return file;
        }
コード例 #5
0
        public static bool HasSubjectEncoding(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            return(command.GetSubjectEncoding() != null);
        }
コード例 #6
0
        public static bool HasBodyEncoding(this SendEMailCommand command)
        {
            Guard.AgainstNull(command, "command");

            return(command.BodyEncoding != null);
        }
コード例 #7
0
        public static void SetMailPriority(this SendEMailCommand command, MailPriority priority)
        {
            Guard.AgainstNull(command, "command");

            command.Priority = priority.ToString();
        }