示例#1
0
        /// <summary>
        /// Create an file attachment for the specific file path
        /// </summary>
        /// <param name="filePath">Attachment file path</param>
        /// <param name="attachmentFileName">Attachment file name</param>
        /// <returns>A leaf-node MIME part that contains an attachment.</returns>
        protected MimePart CreateMimeAttachment(string filePath, string attachmentFileName = null)
        {
            if (string.IsNullOrWhiteSpace(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            if (string.IsNullOrWhiteSpace(attachmentFileName))
            {
                attachmentFileName = Path.GetFileName(filePath);
            }

            return(CreateMimeAttachment(
                       attachmentFileName,
                       _fileProvider.ReadAllBytes(filePath),
                       _fileProvider.GetCreationTime(filePath),
                       _fileProvider.GetLastWriteTime(filePath),
                       _fileProvider.GetLastAccessTime(filePath)));
        }