Esempio n. 1
0
        /// <summary>
        /// Encode the file for inclusion as a mime attachment.
        /// The boundaries are not provided.
        /// </summary>
        /// <returns></returns>

        public String ToMime()
        {
            StringBuilder sb = new StringBuilder();

            if (ContentId != null)
            {
                sb.Append("Content-ID: <" + ContentId + ">\r\n");
            }
            sb.Append("Content-Type: " + mimeType + ";\r\n");
            sb.Append(" name=\"" + MailEncoder.ConvertToQP(name, null) + "\"\r\n");
            sb.Append("Content-Transfer-Encoding: " + encoding + "\r\n");
            sb.Append("Content-Disposition: attachment;\r\n");
            sb.Append(" filename=\"" + MailEncoder.ConvertToQP(name, null) + "\"\r\n\r\n");

            FileStream fin = new FileStream(encodedFilePath, FileMode.Open, FileAccess.Read);

            byte[] bin;

            while (fin.Position != fin.Length)
            {
                bin = new byte[76];
                int len = fin.Read(bin, 0, 76);
                sb.Append(System.Text.Encoding.UTF8.GetString(bin, 0, len) + "\r\n");
            }

            fin.Close();
            return(sb.ToString());
        }
Esempio n. 2
0
        private string GetTextMessageBody(string messageBody, string textType)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("Content-Type: " + textType + ";\r\n");
            sb.Append(" charset=\"" + charset + "\"\r\n");
            sb.Append("Content-Transfer-Encoding: quoted-printable\r\n\r\n");
            sb.Append(MailEncoder.ConvertToQP(messageBody, charset));

            return(sb.ToString());
        }