public static void DumpError(string virtualServer, string errorText) { try { DataSet dataSet = new DataSet("dsEvents"); dataSet.Tables.Add("Events"); dataSet.Tables["Events"].Columns.Add("ID"); dataSet.Tables["Events"].Columns.Add("VirtualServer"); dataSet.Tables["Events"].Columns.Add("CreateDate", typeof(DateTime)); dataSet.Tables["Events"].Columns.Add("Type"); dataSet.Tables["Events"].Columns.Add("Text"); if (File.Exists(SCore.PathFix(Error.m_Path + "Settings\\Events.xml"))) { dataSet.ReadXml(SCore.PathFix(Error.m_Path + "Settings\\Events.xml")); } DataRow dataRow = dataSet.Tables["Events"].NewRow(); dataRow["ID"] = Guid.NewGuid().ToString(); dataRow["VirtualServer"] = virtualServer; dataRow["CreateDate"] = DateTime.Now; dataRow["Type"] = 0; dataRow["Text"] = errorText; dataSet.Tables["Events"].Rows.Add(dataRow); dataSet.WriteXml(SCore.PathFix(Error.m_Path + "Settings\\Events.xml")); } catch { } }
public _MessageRuleAction_FTP_AsyncSend(string server, int port, string user, string password, string folder, Stream data, string fileName) { this.m_Server = server; this.m_Port = port; this.m_User = user; this.m_Password = password; this.m_Folder = folder; this.m_FileName = fileName; this.m_DataStream = new MemoryStream(); SCore.StreamCopy(data, this.m_DataStream); this.m_DataStream.Position = 0L; Thread thread = new Thread(new ThreadStart(this.Send)); thread.Name = "FTP Async Send Thread"; thread.Start(); }
public static void WriteLog(string fileName, string text) { try { fileName = SCore.PathFix(fileName); if (!Directory.Exists(Path.GetDirectoryName(fileName))) { Directory.CreateDirectory(Path.GetDirectoryName(fileName)); } using (FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)) { StreamWriter streamWriter = new StreamWriter(fileStream); streamWriter.BaseStream.Seek(0L, SeekOrigin.End); streamWriter.Write(text + "\r\n"); streamWriter.Flush(); } } catch { } }
private void Post() { try { WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type", "multipart/form-data; boundary=---------------------8c808e3aebd9294"); string text = "-----------------------8c808e3aebd9294\r\n"; text += "Content-Disposition: form-data; name=\"file\"; filename=\"mail.eml\"\r\n"; text += "Content-Type: application/octet-stream\r\n"; text += "\r\n"; MemoryStream memoryStream = new MemoryStream(); byte[] bytes = Encoding.UTF8.GetBytes(text); memoryStream.Write(bytes, 0, bytes.Length); SCore.StreamCopy(this.m_pMessage, memoryStream); bytes = Encoding.UTF8.GetBytes("\r\n-----------------------8c808e3aebd9294--\r\n"); memoryStream.Write(bytes, 0, bytes.Length); webClient.UploadData(this.m_Url, memoryStream.ToArray()); } catch (Exception x) { Error.DumpError(x); } }
internal IMailServerManagementApi LoadApi(string assembly, string typeName, string initString) { string path; if (File.Exists(SCore.PathFix(this.m_StartupPath + "\\" + assembly))) { path = SCore.PathFix(this.m_StartupPath + "\\" + assembly); } else { path = SCore.PathFix(assembly); } Assembly assembly2 = Assembly.LoadFile(path); Type type = assembly2.ExportedTypes.FirstOrDefault((Type x) => x.FullName == typeName && typeof(IMailServerManagementApi).IsAssignableFrom(x)); if (type == null) { throw new Exception("cannot load type with name " + typeName); } return((IMailServerManagementApi)Activator.CreateInstance(type, new object[] { initString })); }
public GlobalMessageRuleActionResult DoActions(DataView dvActions, VirtualServer server, Stream message, string sender, string[] to) { bool deleteMessage = false; string storeFolder = null; string errorText = null; foreach (DataRowView dataRowView in dvActions) { GlobalMessageRuleActionType globalMessageRuleAction_enum = (GlobalMessageRuleActionType)dataRowView["ActionType"]; byte[] data = (byte[])dataRowView["ActionData"]; message.Position = 0L; if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)1) { XmlTable xmlTable = new XmlTable("ActionData"); xmlTable.Parse(data); string value = xmlTable.GetValue("From"); string value2 = xmlTable.GetValue("Message"); MIME_h_Collection mIME_h_Collection = new MIME_h_Collection(new MIME_h_Provider()); mIME_h_Collection.Parse(new SmartStream(message, false)); if (!mIME_h_Collection.Contains("X-LS-MailServer-AutoResponse")) { Mail_Message mail_Message = Mail_Message.ParseFromByte(Encoding.UTF8.GetBytes(value2)); mail_Message.Header.Add(new MIME_h_Unstructured("X-LS-MailServer-AutoResponse", "")); mail_Message.Date = DateTime.Now; if (mail_Message.To == null || mail_Message.To.Count == 0) { if (mail_Message.To == null) { mail_Message.To = new Mail_t_AddressList { new Mail_t_Mailbox(null, sender) }; } else { mail_Message.To.Add(new Mail_t_Mailbox(null, sender)); } } if (mail_Message.Subject != null && mIME_h_Collection.Contains("Subject")) { mail_Message.Subject = mail_Message.Subject.Replace("#SUBJECT", mIME_h_Collection.GetFirst("Subject").ValueToString().Trim()); } if (!string.IsNullOrEmpty(sender)) { server.ProcessAndStoreMessage(value, new string[] { sender }, new MemoryStream(mail_Message.ToByte(new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8)), null); } } } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.DeleteMessage) { XmlTable xmlTable2 = new XmlTable("ActionData"); xmlTable2.Parse(data); deleteMessage = true; } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.ExecuteProgram) { XmlTable xmlTable3 = new XmlTable("ActionData"); xmlTable3.Parse(data); Process.Start(new ProcessStartInfo { FileName = xmlTable3.GetValue("Program"), Arguments = xmlTable3.GetValue("Arguments"), CreateNoWindow = true }); } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.ForwardToEmail) { XmlTable xmlTable4 = new XmlTable("ActionData"); xmlTable4.Parse(data); MIME_h_Collection mIME_h_Collection2 = new MIME_h_Collection(new MIME_h_Provider()); mIME_h_Collection2.Parse(new SmartStream(message, false)); bool flag = false; if (mIME_h_Collection2.Contains("X-LS-MailServer-ForwardedTo")) { MIME_h[] array = mIME_h_Collection2["X-LS-MailServer-ForwardedTo"]; for (int i = 0; i < array.Length; i++) { MIME_h mIME_h = array[i]; if (mIME_h.ValueToString().Trim() == xmlTable4.GetValue("Email")) { flag = true; break; } } } message.Position = 0L; if (!flag) { MemoryStream memoryStream = new MemoryStream(); byte[] bytes = Encoding.UTF8.GetBytes("X-LS-MailServer-ForwardedTo: " + xmlTable4.GetValue("Email") + "\r\n"); memoryStream.Write(bytes, 0, bytes.Length); SCore.StreamCopy(message, memoryStream); server.ProcessAndStoreMessage(sender, new string[] { xmlTable4.GetValue("Email") }, memoryStream, null); } } else if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.ForwardToHost) { XmlTable xmlTable5 = new XmlTable("ActionData"); xmlTable5.Parse(data); for (int j = 0; j < to.Length; j++) { string to2 = to[j]; message.Position = 0L; server.RelayServer.StoreRelayMessage(Guid.NewGuid().ToString(), null, message, HostEndPoint.Parse(xmlTable5.GetValue("Host") + ":" + xmlTable5.GetValue("Port")), sender, to2, null, SMTP_DSN_Notify.NotSpecified, SMTP_DSN_Ret.NotSpecified); } message.Position = 0L; } else { if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.StoreToDiskFolder) { XmlTable xmlTable6 = new XmlTable("ActionData"); xmlTable6.Parse(data); string text = xmlTable6.GetValue("Folder"); if (!text.EndsWith("\\")) { text += "\\"; } if (!Directory.Exists(text)) { continue; } using (FileStream fileStream = File.Create(string.Concat(new string[] { text, DateTime.Now.ToString("ddMMyyyyHHmmss"), "_", Guid.NewGuid().ToString().Replace('-', '_').Substring(0, 8), ".eml" }))) { SCore.StreamCopy(message, fileStream); continue; } } if (globalMessageRuleAction_enum == GlobalMessageRuleActionType.StoreToIMAPFolder) { XmlTable xmlTable7 = new XmlTable("ActionData"); xmlTable7.Parse(data); storeFolder = xmlTable7.GetValue("Folder"); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)8) { XmlTable xmlTable8 = new XmlTable("ActionData"); xmlTable8.Parse(data); Mail_Message mail_Message2 = Mail_Message.ParseFromStream(message); mail_Message2.Header.Add(new MIME_h_Unstructured(xmlTable8.GetValue("HeaderFieldName"), xmlTable8.GetValue("HeaderFieldValue"))); message.SetLength(0L); mail_Message2.ToStream(message, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)9) { XmlTable xmlTable9 = new XmlTable("ActionData"); xmlTable9.Parse(data); Mail_Message mail_Message3 = Mail_Message.ParseFromStream(message); mail_Message3.Header.RemoveAll(xmlTable9.GetValue("HeaderFieldName")); message.SetLength(0L); mail_Message3.ToStream(message, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)10) { XmlTable xmlTable10 = new XmlTable("ActionData"); xmlTable10.Parse(data); errorText = xmlTable10.GetValue("ErrorText"); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)11) { XmlTable xmlTable11 = new XmlTable("ActionData"); xmlTable11.Parse(data); new _MessageRuleAction_FTP_AsyncSend(xmlTable11.GetValue("Server"), Convert.ToInt32(xmlTable11.GetValue("Port")), xmlTable11.GetValue("User"), xmlTable11.GetValue("Password"), xmlTable11.GetValue("Folder"), message, DateTime.Now.ToString("ddMMyyyyHHmmss") + "_" + Guid.NewGuid().ToString().Replace('-', '_').Substring(0, 8) + ".eml"); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)12) { XmlTable xmlTable12 = new XmlTable("ActionData"); xmlTable12.Parse(data); Mail_Message mail_Message4 = Mail_Message.ParseFromStream(message); if (!mail_Message4.Header.Contains("Newsgroups:")) { mail_Message4.Header.Add(new MIME_h_Unstructured("Newsgroups:", xmlTable12.GetValue("Newsgroup"))); } new _MessageRuleAction_NNTP_Async(xmlTable12.GetValue("Server"), Convert.ToInt32(xmlTable12.GetValue("Port")), xmlTable12.GetValue("Newsgroup"), new MemoryStream(mail_Message4.ToByte(new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8))); } else if (globalMessageRuleAction_enum == (GlobalMessageRuleActionType)13) { XmlTable xmlTable13 = new XmlTable("ActionData"); xmlTable13.Parse(data); new _MessageRuleAction_HTTP_Async(xmlTable13.GetValue("URL"), message); } } } return(new GlobalMessageRuleActionResult(deleteMessage, storeFolder, errorText)); }
private bool Match(bool syntaxCheckOnly, System.NetworkToolkit.StringReader r, string mailFrom, string[] rcptTo, SMTP_Session smtpSession, Mail_Message mime, int messageSize) { GlobalMessageRuleProcessor.PossibleClauseItem possibleClauseItem = (GlobalMessageRuleProcessor.PossibleClauseItem) 56; bool flag = false; r.ReadToFirstChar(); if (r.Available == 0L) { throw new Exception("Invalid syntax: '" + this.ClauseItemsToString(possibleClauseItem) + "' expected !"); } while (r.Available > 0L) { r.ReadToFirstChar(); if (syntaxCheckOnly) { flag = true; } if (r.StartsWith("(")) { flag = this.Match(syntaxCheckOnly, new System.NetworkToolkit.StringReader(r.ReadParenthesized()), mailFrom, rcptTo, smtpSession, mime, messageSize); possibleClauseItem = (GlobalMessageRuleProcessor.PossibleClauseItem) 56; } else if (r.StartsWith("and", false)) { if ((possibleClauseItem & GlobalMessageRuleProcessor.PossibleClauseItem.AND) == (GlobalMessageRuleProcessor.PossibleClauseItem) 0) { throw new Exception("Invalid syntax: '" + this.ClauseItemsToString(possibleClauseItem) + "' expected !"); } if (!flag) { return(false); } r.ReadWord(); r.ReadToFirstChar(); flag = this.Match(syntaxCheckOnly, r, mailFrom, rcptTo, smtpSession, mime, messageSize); possibleClauseItem = (GlobalMessageRuleProcessor.PossibleClauseItem) 56; } else if (r.StartsWith("or", false)) { if ((possibleClauseItem & GlobalMessageRuleProcessor.PossibleClauseItem.OR) == (GlobalMessageRuleProcessor.PossibleClauseItem) 0) { throw new Exception("Invalid syntax: '" + this.ClauseItemsToString(possibleClauseItem) + "' expected !"); } r.ReadWord(); r.ReadToFirstChar(); if (flag) { this.Match(syntaxCheckOnly, r, mailFrom, rcptTo, smtpSession, mime, messageSize); } else { flag = this.Match(syntaxCheckOnly, r, mailFrom, rcptTo, smtpSession, mime, messageSize); } possibleClauseItem = (GlobalMessageRuleProcessor.PossibleClauseItem) 56; } else if (r.StartsWith("not", false)) { if ((possibleClauseItem & GlobalMessageRuleProcessor.PossibleClauseItem.NOT) == (GlobalMessageRuleProcessor.PossibleClauseItem) 0) { throw new Exception("Invalid syntax: '" + this.ClauseItemsToString(possibleClauseItem) + "' expected !"); } r.ReadWord(); r.ReadToFirstChar(); flag = !this.Match(syntaxCheckOnly, r, mailFrom, rcptTo, smtpSession, mime, messageSize); possibleClauseItem = (GlobalMessageRuleProcessor.PossibleClauseItem) 48; } else { if ((possibleClauseItem & GlobalMessageRuleProcessor.PossibleClauseItem.Matcher) == (GlobalMessageRuleProcessor.PossibleClauseItem) 0) { throw new Exception(string.Concat(new string[] { "Invalid syntax: '", this.ClauseItemsToString(possibleClauseItem), "' expected ! \r\n\r\n Near: '", r.OriginalString.Substring(0, r.Position), "'" })); } string text = r.ReadWord(); if (text == null) { throw new Exception("Invalid syntax: matcher is missing !"); } text = text.ToLower(); string[] array = new string[0]; if (text == "smtp.mail_from") { if (!syntaxCheckOnly) { array = new string[] { mailFrom }; } } else if (text == "smtp.rcpt_to") { if (!syntaxCheckOnly) { array = rcptTo; } } else if (text == "smtp.ehlo") { if (!syntaxCheckOnly) { array = new string[] { smtpSession.EhloHost }; } } else if (text == "smtp.authenticated") { if (!syntaxCheckOnly && smtpSession != null) { array = new string[] { smtpSession.IsAuthenticated.ToString() }; } } else if (text == "smtp.user") { if (!syntaxCheckOnly && smtpSession != null && smtpSession.AuthenticatedUserIdentity != null) { array = new string[] { smtpSession.AuthenticatedUserIdentity.Name }; } } else if (text == "smtp.remote_ip") { if (!syntaxCheckOnly && smtpSession != null) { array = new string[] { smtpSession.RemoteEndPoint.Address.ToString() }; } } else if (text == "message.size") { if (!syntaxCheckOnly) { array = new string[] { messageSize.ToString() }; } } else if (text == "message.header") { string text2 = r.ReadWord(); if (text2 == null) { throw new Exception("Match source MainHeaderField HeaderFieldName is missing ! Syntax:{MainHeaderField <SP> \"HeaderFieldName:\"}"); } if (!syntaxCheckOnly && mime.Header.Contains(text2)) { MIME_h[] array2 = mime.Header[text2]; array = new string[array2.Length]; for (int i = 0; i < array.Length; i++) { array[i] = array2[i].ValueToString(); } } } else if (text == "message.all_headers") { string text3 = r.ReadWord(); if (text3 == null) { throw new Exception("Match source MainHeaderField HeaderFieldName is missing ! Syntax:{MainHeaderField <SP> \"HeaderFieldName:\"}"); } if (!syntaxCheckOnly) { List <string> list = new List <string>(); MIME_Entity[] allEntities = mime.AllEntities; for (int j = 0; j < allEntities.Length; j++) { MIME_Entity mIME_Entity = allEntities[j]; if (mIME_Entity.Header.Contains(text3)) { MIME_h[] array3 = mIME_Entity.Header[text3]; for (int k = 0; k < array3.Length; k++) { list.Add(array3[k].ValueToString()); } } } array = list.ToArray(); } } else if (text == "message.body_text") { if (!syntaxCheckOnly) { array = new string[] { mime.BodyText }; } } else if (text == "message.body_html") { if (!syntaxCheckOnly) { array = new string[] { mime.BodyHtmlText }; } } else if (text == "message.content_md5") { if (!syntaxCheckOnly) { List <string> list2 = new List <string>(); MIME_Entity[] allEntities2 = mime.AllEntities; for (int l = 0; l < allEntities2.Length; l++) { MIME_Entity mIME_Entity2 = allEntities2[l]; try { if (mIME_Entity2.Body is MIME_b_SinglepartBase) { byte[] data = ((MIME_b_SinglepartBase)mIME_Entity2.Body).Data; if (data != null) { MD5CryptoServiceProvider mD5CryptoServiceProvider = new MD5CryptoServiceProvider(); list2.Add(Encoding.UTF8.GetString(mD5CryptoServiceProvider.ComputeHash(data))); } } } catch { } } array = list2.ToArray(); } } else if (text == "sys.date_time") { if (!syntaxCheckOnly) { array = new string[] { DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss") }; } } else if (text == "sys.date") { if (!syntaxCheckOnly) { array = new string[] { DateTime.Today.ToString("dd.MM.yyyy") }; } } else if (text == "sys.time") { if (!syntaxCheckOnly) { array = new string[] { DateTime.Now.ToString("HH:mm:ss") }; } } else if (text == "sys.day_of_week") { if (!syntaxCheckOnly) { array = new string[] { DateTime.Today.DayOfWeek.ToString() }; } } else { if (!(text == "sys.day_of_year")) { throw new Exception("Unknown match source '" + text + "' !"); } if (!syntaxCheckOnly) { array = new string[] { DateTime.Today.ToString("M") }; } } flag = false; text = r.ReadWord(true, new char[] { ' ' }, true); if (text == null) { throw new Exception("Invalid syntax: operator is missing ! \r\n\r\n Near: '" + r.OriginalString.Substring(0, r.Position) + "'"); } text = text.ToLower(); if (text == "*") { string text4 = r.ReadWord(); if (text4 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text4 = text4.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int m = 0; m < array4.Length; m++) { string text5 = array4[m]; if (SCore.IsAstericMatch(text4, text5.ToLower())) { flag = true; break; } } } } else if (text == "!*") { string text6 = r.ReadWord(); if (text6 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text6 = text6.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text7 = array4[j]; if (SCore.IsAstericMatch(text6, text7.ToLower())) { flag = false; break; } } } } else if (text == "==") { string text8 = r.ReadWord(); if (text8 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text8 = text8.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text9 = array4[j]; if (text8 == text9.ToLower()) { flag = true; break; } } } } else if (text == "!=") { string text10 = r.ReadWord(); if (text10 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text10 = text10.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text11 = array4[j]; if (text10 == text11.ToLower()) { flag = false; break; } flag = true; } } } else if (text == ">=") { string text12 = r.ReadWord(); if (text12 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text12 = text12.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text13 = array4[j]; if (text13.ToLower().CompareTo(text12) >= 0) { flag = true; break; } } } } else if (text == "<=") { string text14 = r.ReadWord(); if (text14 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text14 = text14.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text15 = array4[j]; if (text15.ToLower().CompareTo(text14) <= 0) { flag = true; break; } } } } else if (text == ">") { string text16 = r.ReadWord(); if (text16 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text16 = text16.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text17 = array4[j]; if (text17.ToLower().CompareTo(text16) > 0) { flag = true; break; } } } } else if (text == "<") { string text18 = r.ReadWord(); if (text18 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text18 = text18.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text19 = array4[j]; if (text19.ToLower().CompareTo(text18) < 0) { flag = true; break; } } } } else { if (!(text == "regex")) { throw new Exception("Unknown keword '" + text + "' !"); } string text20 = r.ReadWord(); if (text20 == null) { throw new Exception("Invalid syntax: <SP> \"value\" is missing !"); } text20 = text20.ToLower(); if (!syntaxCheckOnly) { string[] array4 = array; for (int j = 0; j < array4.Length; j++) { string text21 = array4[j]; if (Regex.IsMatch(text20, text21.ToLower())) { flag = true; break; } } } } possibleClauseItem = (GlobalMessageRuleProcessor.PossibleClauseItem) 6; } } return(flag); }
public static Mail_Message CreateDsnMessage(string to, string subject, string rtfText, string envelopeID, DateTime arrivalDate, string receivedFromMTA, string reportingMTA, string originalRecipient, string finalRecipient, string action, string statusCode_text, string remoteMTA, DateTime lastAttempt, DateTime retryUntil, SMTP_DSN_Ret ret, Mail_Message message) { rtfText = rtfText.Replace("\r\n", "\n").Replace("\n", "\r\n"); Mail_Message mail_Message = new Mail_Message(); mail_Message.MimeVersion = "1.0"; mail_Message.Date = DateTime.Now; mail_Message.From = new Mail_t_MailboxList(); mail_Message.From.Add(new Mail_t_Mailbox("Mail Delivery Subsystem", "postmaster@local")); mail_Message.To = new Mail_t_AddressList(); mail_Message.To.Add(new Mail_t_Mailbox(null, to)); mail_Message.Subject = subject; MIME_h_ContentType mIME_h_ContentType = new MIME_h_ContentType(MIME_MediaTypes.Multipart.report); mIME_h_ContentType.Parameters["report-type"] = "delivery-status"; mIME_h_ContentType.Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.'); MIME_b_MultipartReport mIME_b_MultipartReport = new MIME_b_MultipartReport(mIME_h_ContentType); mail_Message.Body = mIME_b_MultipartReport; MIME_Entity mIME_Entity = new MIME_Entity(); MIME_b_MultipartAlternative mIME_b_MultipartAlternative = new MIME_b_MultipartAlternative(new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative) { Param_Boundary = Guid.NewGuid().ToString().Replace('-', '.') }); mIME_Entity.Body = mIME_b_MultipartAlternative; mIME_b_MultipartReport.BodyParts.Add(mIME_Entity); MIME_Entity mIME_Entity2 = new MIME_Entity(); MIME_b_Text mIME_b_Text = new MIME_b_Text(MIME_MediaTypes.Text.plain); mIME_Entity2.Body = mIME_b_Text; mIME_b_Text.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, SCore.RtfToText(rtfText)); mIME_b_MultipartAlternative.BodyParts.Add(mIME_Entity2); MIME_Entity mIME_Entity3 = new MIME_Entity(); MIME_b_Text mIME_b_Text2 = new MIME_b_Text(MIME_MediaTypes.Text.html); mIME_Entity3.Body = mIME_b_Text2; mIME_b_Text2.SetText(MIME_TransferEncodings.QuotedPrintable, Encoding.UTF8, SCore.RtfToHtml(rtfText)); mIME_b_MultipartAlternative.BodyParts.Add(mIME_Entity3); MIME_Entity mIME_Entity4 = new MIME_Entity(); MIME_b_Message mIME_b_Message = new MIME_b_Message(MIME_MediaTypes.Message.delivery_status); mIME_Entity4.Body = mIME_b_Message; StringBuilder stringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(envelopeID)) { stringBuilder.Append("Original-Envelope-Id: " + envelopeID + "\r\n"); } stringBuilder.Append("Arrival-Date: " + MIME_Utils.DateTimeToRfc2822(arrivalDate) + "\r\n"); if (!string.IsNullOrEmpty(receivedFromMTA)) { stringBuilder.Append("Received-From-MTA: dns; " + receivedFromMTA + "\r\n"); } stringBuilder.Append("Reporting-MTA: dns; " + reportingMTA + "\r\n"); stringBuilder.Append("\r\n"); if (!string.IsNullOrEmpty(originalRecipient)) { stringBuilder.Append("Original-Recipient: " + originalRecipient + "\r\n"); } stringBuilder.Append("Final-Recipient: rfc822;" + finalRecipient + "\r\n"); stringBuilder.Append("Action: " + action + "\r\n"); stringBuilder.Append("Status: " + statusCode_text.Substring(0, 1) + ".0.0\r\n"); if (!string.IsNullOrEmpty(statusCode_text)) { stringBuilder.Append("Diagnostic-Code: smtp; " + statusCode_text + "\r\n"); } if (!string.IsNullOrEmpty(remoteMTA)) { stringBuilder.Append("Remote-MTA: dns; " + remoteMTA + "\r\n"); } if (lastAttempt != DateTime.MinValue) { stringBuilder.Append("Last-Attempt-Date: " + MIME_Utils.DateTimeToRfc2822(lastAttempt) + "\r\n"); } if (retryUntil != DateTime.MinValue) { stringBuilder.Append("Will-Retry-Until: " + MIME_Utils.DateTimeToRfc2822(retryUntil) + "\r\n"); } stringBuilder.Append("\r\n"); mIME_b_Message.SetData(new MemoryStream(Encoding.UTF8.GetBytes(stringBuilder.ToString())), MIME_TransferEncodings.EightBit); mIME_b_MultipartReport.BodyParts.Add(mIME_Entity4); if (message != null) { MIME_Entity mIME_Entity5 = new MIME_Entity(); MIME_b_MessageRfc822 mIME_b_MessageRfc = new MIME_b_MessageRfc822(); mIME_Entity5.Body = mIME_b_MessageRfc; if (ret == SMTP_DSN_Ret.FullMessage) { mIME_b_MessageRfc.Message = message; } else { MemoryStream memoryStream = new MemoryStream(); message.Header.ToStream(memoryStream, null, null); memoryStream.Position = 0L; mIME_b_MessageRfc.Message = Mail_Message.ParseFromStream(memoryStream); } mIME_b_MultipartReport.BodyParts.Add(mIME_Entity5); } return(mail_Message); }