/** * @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)); }
/** * @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)); }
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); }