예제 #1
0
        /**
         * @param string path
         * @param string|null contentType
         * @return IAttachment
         * @since 13.0.0
         */
        public IAttachment createAttachmentFromPath(string path, string contentType = null)
        {
            var attachment = new FluentEmail.Core.Models.Attachment();

            byte[]       byteArray = File.ReadAllBytes(path);
            MemoryStream stream    = new MemoryStream(byteArray);

            attachment.Data        = stream;
            attachment.ContentType = contentType;
            return(new Attachment(attachment));
        }
예제 #2
0
        /**
         * @param string|null data
         * @param string|null filename
         * @param string|null contentType
         * @return IAttachment
         * @since 13.0.0
         */
        public IAttachment createAttachment(string data, string filename, string contentType)
        {
            var attachment = new FluentEmail.Core.Models.Attachment();

            byte[]       byteArray = Encoding.ASCII.GetBytes(data);
            MemoryStream stream    = new MemoryStream(byteArray);

            attachment.Data        = stream;
            attachment.Filename    = filename;
            attachment.ContentType = contentType;
            return(new Attachment(attachment));
        }
예제 #3
0
        public async static Task <Attachment> LoadAttachment(string path, string name, string mimetype)
        {
            var memory = new MemoryStream();

            using (var stream = new FileStream(path, FileMode.Open)) {
                await stream.CopyToAsync(memory);
            }

            memory.Position = 0;

            var result = new Attachment();

            result.Data        = memory;
            result.Filename    = name;
            result.ContentType = mimetype;
            return(result);
        }