Esempio n. 1
0
        /// <summary>
        /// Constructs an attachment from a local file
        /// </summary>
        /// <param name="path">Path of local file to send</param>
        /// <param name="filename_send">The filename of the atachment</param>
        /// <param name="content_type">The Mime Content-Type </param>
        /// <param name="disposition">The Mime disposition</param>
        public MimeAttachment(string path, string filename_send, string content_type, MimeDisposition disposition)
        {
            m_headers["Content-Type"] = content_type + ";\r\n        name=\"" + filename_send + "\"" + endl;
            m_headers["Content-Transfer-Encoding"] = "Base64";
            if (disposition == MimeDisposition.attachment)
            {
                m_headers["Content-Disposition"] = "attachment;\r\n        filename=\"" + filename_send + "\"" + endl;
            }
            else
            {
                m_headers["Content-Disposition"] = "inline;\r\n        filename=\"" + filename_send + "\"" + endl;
            }

            m_bodyBuilder = new StringBuilder();
            m_bodyBuilder.Append(endl);

            System.IO.FileStream file = new System.IO.FileStream(path, System.IO.FileMode.Open,
                                                                 System.IO.FileAccess.Read);
            System.IO.BinaryReader read = new System.IO.BinaryReader(file);

            // Attachment limited to 2Go !
            Byte [] buf = read.ReadBytes((int)file.Length);
            read.Close();

            m_bodyBuilder.Append(MimeEncoder.ByteBase64(buf, 78));
            m_bodyBuilder.Append(endl);
            m_body        = m_bodyBuilder.ToString();
            m_bodyBuilder = null;
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs an attachment from a memory buffer
        /// </summary>
        /// <param name="name">The attachment name</param>
        /// <param name="filename_send">The attachment filename if need</param>
        /// <param name="content_type">The content type</param>
        /// <param name="buf">The buffer to send</param>
        /// <param name="disposition">The file disposition</param>
        public MimeAttachment(string name, string filename_send, string content_type, Byte[] buf, MimeDisposition disposition)
        {
            m_headers["Content-Type"] = content_type + ";\r\n        name=\"" + name + "\"" + endl;
            m_headers["Content-Transfer-Encoding"] = "Base64";

            if (disposition == MimeDisposition.attachment)
            {
                m_headers["Content-Disposition"] = "attachment;\r\n        filename=\"" + filename_send + "\"" + endl;
            }
            else
            {
                m_headers["Content-Disposition"] = "inline;\r\n        filename=\"" + filename_send + "\"" + endl;
            }


            m_bodyBuilder = new StringBuilder();
            m_bodyBuilder.Append(endl);
            m_bodyBuilder.Append(MimeEncoder.ByteBase64(buf, 78));
            m_bodyBuilder.Append(endl);
            m_body        = m_bodyBuilder.ToString();
            m_bodyBuilder = null;
        }