Example #1
0
        const string CONTENT_ID       = "Content-ID:<{0}>";                                // 图片的content ID


        /// <summary>
        /// 附件嵌入图片发送
        /// </summary>
        /// <param name="attchments"></param>
        /// <param name="writer"></param>
        /// <param name="encoding"></param>
        public static void SendAttchments(List <MailAttchment> attchments, Stream writer, string encoding)
        {
            foreach (var att in attchments)
            {
                byte[] fileDate;
                string fileName = "";
                //读取文件内容
                using (FileStream file = new FileStream(att.FileName, FileMode.Open))
                {
                    fileDate = new byte[Convert.ToInt32(file.Length)];
                    file.Read(fileDate, 0, fileDate.Length);
                    fileName = Path.GetFileName(att.FileName);
                }
                Writer(SP, encoding, writer);
                Writer(string.Format(FILE_HEADER, fileName), encoding, writer); //文件头
                Writer(string.Format(FILE_DESCRIPTION, fileName), encoding, writer);
                if (att.ContentID != null)
                {
                    Writer(string.Format(CONTENT_ID, att.ContentID), encoding, writer); // 图片附件contentID
                }
                Writer(Formater.EncodingFormat("base64"), encoding, writer);            //编码

                Writer("\r\n", encoding, writer);
                Writer(Convert.ToBase64String(fileDate), encoding, writer); //文件内容
                Writer("", encoding, writer);                               //完成发送
            }
        }
Example #2
0
        /// <summary>
        /// 内容发送
        /// </summary>
        /// <param name="body"></param>
        /// <param name="writer"></param>
        /// <param name="encoding"></param>
        /// <param name="isHtml"></param>
        public static void SendBody(string body, Stream writer, string encoding, bool isHtml)
        {
            Writer(Formater.BodyHeaderFormat(isHtml, encoding), encoding, writer);
            Writer(Formater.EncodingFormat("base64"), encoding, writer);
            Writer("\r\n", encoding, writer);

            Writer(Convert.ToBase64String(Encoding.GetEncoding(encoding).GetBytes(body)), encoding, writer);

            Writer("", encoding, writer);
        }
Example #3
0
        const string FILE_DESCRIPTION = "Content-Disposition:attachment;filename=\"{0}\""; //文件注解

        /// <summary>
        /// 附件发送
        /// </summary>
        /// <param name="attchments"></param>
        /// <param name="writer"></param>
        /// <param name="encoding"></param>
        public static void SendAttchments(List <string> attchments, Stream writer, string encoding)
        {
            foreach (string filePath in attchments)
            {
                byte[] fileDate;
                string fileName = "";
                //读取文件内容
                using (FileStream file = new FileStream(filePath, FileMode.Open))
                {
                    fileDate = new byte[Convert.ToInt32(file.Length)];
                    file.Read(fileDate, 0, fileDate.Length);
                    fileName = Path.GetFileName(filePath);
                }
                Writer(SP, encoding, writer);
                Writer(string.Format(FILE_HEADER, fileName), encoding, writer); //文件头
                Writer(Formater.EncodingFormat("base64"), encoding, writer);    //编码

                Writer("\r\n", encoding, writer);
                Writer(Convert.ToBase64String(fileDate), encoding, writer); //文件内容
                Writer("", encoding, writer);                               //完成发送
            }
        }
Example #4
0
 /// <summary>
 /// 邮件头发送
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="message"></param>
 public static void SendHeader(Stream writer, MailMessage message)
 {
     Writer(Formater.DateFormat(DateTime.Now), message.Encoding, writer);                          //日期
     Writer(Formater.FormFormat(message.DisplayFrom, message.Encoding), message.Encoding, writer); //发件人
     Writer(Formater.TosFormat(message.Tos, message.Encoding), message.Encoding, writer);          //收件人
     Writer("REPLY-TO:" + message.DisplayFrom.MailAddress, message.Encoding, writer);              //回复地址
     if (message.CCs.Count > 0)
     {
         Writer(Formater.CCsFormat(message.CCs, message.Encoding), message.Encoding, writer); //抄送
     }
     if (message.Mccs.Count > 0)
     {
         Writer(Formater.MCCsFormat(message.Mccs, message.Encoding), message.Encoding, writer);   //密送
     }
     Writer(Formater.PriorityFormat(message.priority), message.Encoding, writer);                 //优先级
     Writer(Formater.SubjectFormat(message.Subject, message.Encoding), message.Encoding, writer); //标题
     Writer(Formater.EncodingFormat("base64"), message.Encoding, writer);                         //编码
     Writer("X-Mailer:DS Mail Sender V1.0", message.Encoding, writer);                            //发件人
     Writer(Formater.MessageIdFormat(System.Guid.NewGuid().ToString()), message.Encoding, writer);
     Writer("MIME-Version:1.0", message.Encoding, writer);
     Writer("Content-Type: multipart/mixed; boundary=\"mailboundary\"\r\n", message.Encoding, writer); //分隔符
     Writer(SP, message.Encoding, writer);                                                             //分隔符
 }