Пример #1
0
        public static LinkedResource ToLinkedResource(
            this EmailAttachment emailAttachment,
            string contentId)
        {
            new { emailAttachment }.AsArg().Must().NotBeNull();

            var mimeTypeName = emailAttachment.MediaType.ToMimeTypeName();

            var contentType = new ContentType {
                MediaType = mimeTypeName
            };

            if (!string.IsNullOrWhiteSpace(emailAttachment.FileName))
            {
                contentType.Name = emailAttachment.FileName;
            }

            var contentStream = new MemoryStream(emailAttachment.FileBytes);

            var result = new LinkedResource(contentStream, contentType)
            {
                ContentId   = contentId,
                ContentLink = new Uri("cid:" + contentId),
            };

            return(result);
        }
Пример #2
0
        public static Attachment ToAttachment(
            this EmailAttachment emailAttachment)
        {
            new { emailAttachment }.AsArg().Must().NotBeNull();

            var mimeTypeName = emailAttachment.MediaType.ToMimeTypeName();

            var contentType = new ContentType {
                MediaType = mimeTypeName
            };

            if (!string.IsNullOrWhiteSpace(emailAttachment.FileName))
            {
                contentType.Name = emailAttachment.FileName;
            }

            var contentStream = new MemoryStream(emailAttachment.FileBytes);

            var result = new Attachment(contentStream, contentType);

            result.ContentDisposition.Size = emailAttachment.FileBytes.Length;

            if (!string.IsNullOrWhiteSpace(emailAttachment.FileName))
            {
                result.ContentDisposition.FileName = emailAttachment.FileName;
            }

            if (emailAttachment.FileNameEncodingKind != null)
            {
                result.NameEncoding = emailAttachment.FileNameEncodingKind?.ToEncoding();
            }

            return(result);
        }