public string PersistEmail(ref Email email, string uniqueId)
        {
            if (null == this.repositoryBaseDirectory)
            {
                throw new InvalidProgramException("No Email repository base directory setting could be found in the application configuration file.");
            }

            var repositoryRelativeDirectory = string.Format(
                "{0}\\{1}\\{2}",
                DateTime.Today.Year,
                DateTime.Today.Month,
                DateTime.Today.Day);
            var repositoryFinalDirectory = Path.Combine(this.repositoryBaseDirectory, repositoryRelativeDirectory);

            DirectoryUtils.EnsureExists(repositoryFinalDirectory);

            var filename = string.Format("{0}.eml", uniqueId);

            foreach (var invalidCharacter in Path.GetInvalidFileNameChars())
            {
                if (filename.Contains(invalidCharacter))
                {
                    filename = filename.Replace(invalidCharacter, '_');
                }
            }

            var repositoryAbsolutePath = Path.Combine(repositoryFinalDirectory, filename);

            using (var fileStream = new FileStream(repositoryAbsolutePath, FileMode.Create))
            {
                if (email.MimeBytes == null)
                {
                    email.MimeBytes = EmailUtilities.GetEmailBytes(email);
                }

                fileStream.Write(email.MimeBytes, 0, email.MimeBytes.Length);
            }

            email.FileName     = filename;
            email.PhysicalPath = repositoryFinalDirectory;

            return(uniqueId);
        }
Ejemplo n.º 2
0
 public byte[] GetEmailMimeBytes(Email email)
 {
     return(EmailUtilities.GetEmailBytes(email));
 }
Ejemplo n.º 3
0
 public byte[] GetEmailMimeBytes(Domain.Email.Models.Email email)
 {
     return(EmailUtilities.GetEmailBytes(email));
 }