public MimePart(byte[] attachment, string filename) { this._binaryContent = attachment; string ext = ".ext"; if (!string.IsNullOrEmpty(filename)) { var collection = filename.Split('.'); if (collection.Length > 1) { ext = collection[collection.Length - 1]; } } var encoded_name = Codec.RFC2047Encode(filename); this.ContentType.MimeType = MimeTypesHelper.GetMimeqType(ext); this.ContentDisposition.FileName = encoded_name; this.ContentName = encoded_name; 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); } }
public MimePart(byte[] content, string fileName, string charset = null) : this() { BinaryContent = content; var ext = ".ext"; if (!string.IsNullOrEmpty(fileName)) { var collection = fileName.Split('.'); if (collection.Length > 1) { ext = collection[collection.Length - 1]; } } ContentType.MimeType = MimeTypesHelper.GetMimeqType(ext); ContentDisposition.FileName = Codec.RFC2047Encode(fileName); ContentName = fileName; BuildTextContent(charset); }