/// <summary> /// Creates a MimePart object with the content of the file located at the given path. /// </summary> /// <param name="path">File containing the content of the MimePart.</param> /// <param name="generateContentId">If true, a Content-ID Header field will be added to allow referencing of this part in the message.</param> public MimePart(string path, bool generateContentId) { System.IO.FileStream fs = System.IO.File.OpenRead(path); this._binaryContent = new byte[(int)fs.Length]; fs.Read(this.BinaryContent, 0, (int)fs.Length); fs.Close(); this.ContentType.MimeType = MimeTypesHelper.GetMimeqType(System.IO.Path.GetExtension(path)); this.ContentDisposition.FileName = System.IO.Path.GetFileName(path); this.ContentName = System.IO.Path.GetFileName(path); if (generateContentId) { this.SetContentId(); } if (this.ContentType.MimeType.ToLower().IndexOf("text/") != -1) { this.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable; this.TextContent = System.Text.Encoding.GetEncoding("utf-8").GetString(this.BinaryContent, 0, this.BinaryContent.Length); } else { this.ContentTransferEncoding = ContentTransferEncoding.Base64; this.TextContent = System.Convert.ToBase64String(this.BinaryContent); } }
/// <summary> /// Creates a MimePart object with the content of the file located at the given path. /// </summary> /// <param name="path">File containing the content of the MimePart.</param> /// <param name="contentId">The Content-ID Header field will be used for the part.</param> /// <param name="charset">If the file contains text, the charset of the text can be provided to ensure better handling.</param> public MimePart(string path, string contentId, string charset = null) : this(File.ReadAllBytes(path), MimeTypesHelper.GetMimeqType(Path.GetExtension(path)), Path.GetFileName(path), charset) { ContentId = contentId; }
public MimePart(byte[] attachment, string fileExtension) : this(attachment, MimeTypesHelper.GetMimeqType(fileExtension), fileExtension) { }