/// <summary> /// The MIME representation of the header. /// </summary> /// <param name="removeBlindCopies">if set to <c>true</c> remove blind copies (BCC).</param> /// <param name="forceBase64Encoding">if set to <c>true</c> forces inner elements to be base64 encoded</param> /// <returns></returns> public string ToHeaderString(bool removeBlindCopies, bool forceBase64Encoding = false) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); /*foreach (TraceInfo trace in this.Trace) sb.AppendLine("Received: " + trace.ToString()); * if (!this.From.Email.Equals(string.Empty)) sb.AppendLine("From: " + this.From.Merged); * if (!this.Sender.Email.Equals(string.Empty)) sb.AppendLine("Sender: " + this.Sender.Merged); * if (this.To.Count > 0) sb.AppendLine("To: " + this.To.Merged); * if (this.Cc.Count > 0) sb.AppendLine("Cc: " + this.Cc.Merged); * if (this.Bcc.Count > 0) sb.AppendLine("Bcc: " + this.Bcc.Merged); * if (!this.ReplyTo.Email.Equals(string.Empty)) sb.AppendLine("Reply-to: " + this.ReplyTo.Merged);*/ foreach (TraceInfo trace in Trace) { AddHeaderField("Received", trace.ToString()); } if (!From.Email.Equals(string.Empty)) { AddHeaderField("From", From.Merged); } if (!Sender.Email.Equals(string.Empty)) { AddHeaderField("Sender", Sender.Merged); } if (To.Count > 0) { AddHeaderField("To", To.Merged); } if (Cc.Count > 0) { AddHeaderField("Cc", Cc.Merged); } if (Bcc.Count > 0 && !removeBlindCopies) { AddHeaderField("Bcc", Bcc.Merged); } if (!ReplyTo.Email.Equals(string.Empty)) { AddHeaderField("Reply-To", ReplyTo.Merged); } if (Date.Equals(DateTime.MinValue)) { Date = DateTime.Now; } if (string.IsNullOrEmpty(MessageId)) { MessageId = "<AU" + Codec.GetUniqueString() + "@" + System.Net.Dns.GetHostName() + ">"; } if (ContentType.MimeType.Length > 0) { string contentType = ContentType.ToString(); contentType = contentType.Substring(contentType.IndexOf(":") + 1).TrimStart(' '); AddHeaderField("Content-Type", contentType); } if (ContentDisposition.Disposition.Length > 0) { string contentDisposition = ContentDisposition.ToString(); contentDisposition = contentDisposition.Substring(contentDisposition.IndexOf(":") + 1).TrimStart(' '); AddHeaderField("Content-Disposition", contentDisposition); } if (forceBase64Encoding) { AddHeaderField("Content-Transfer-Encoding", "base64"); } else if (ContentType.Type.Equals("text")) { AddHeaderField("Content-Transfer-Encoding", "quoted-printable"); } System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); Version v = asm.GetName().Version; AddHeaderField("X-Mailer", "ActiveUp.MailSystem " + v.Major + "." + v.Minor + "." + v.Build + " www.activeup.com"); foreach (string key in HeaderFields.AllKeys) { for (int i = 0; i < HeaderFields.GetValues(key).Length; i++) { sb.Append(HeaderFieldNames.GetValues(key)[i] + ": " + HeaderFields.GetValues(key)[i] + "\r\n"); } } return(sb.ToString().TrimEnd('\r', '\n')); }