/// <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>
 /// <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, bool generateContentId, string charset)
 {
     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.Charset = charset;
         this.ContentTransferEncoding = ContentTransferEncoding.QuotedPrintable;
         this.TextContent             = System.Text.Encoding.GetEncoding(charset).GetString(this.BinaryContent, 0, this.BinaryContent.Length);
     }
     else
     {
         this.ContentTransferEncoding = ContentTransferEncoding.Base64;
         this.TextContent             = System.Convert.ToBase64String(this.BinaryContent);
     }
 }
        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);
            }
        }
Exemple #3
0
 /// <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>
 /// <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, bool generateContentId, string charset = null)
     : this(File.ReadAllBytes(path), MimeTypesHelper.GetMimeqType(Path.GetExtension(path)), Path.GetFileName(path), charset)
 {
     if (generateContentId)
     {
         SetContentId();
     }
 }
        public MimePart(byte[] attachment, string filename)
        {
            this._binaryContent              = attachment;
            this.ContentType.MimeType        = MimeTypesHelper.GetMimeqType(filename);
            this.ContentDisposition.FileName = filename;
            this.ContentName = filename;

            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);
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
 /// <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;
 }
Exemple #7
0
 public MimePart(byte[] attachment, string fileExtension)
     : this(attachment, MimeTypesHelper.GetMimeqType(fileExtension), fileExtension)
 {
 }