/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner SMTP server session.</param> /// <param name="to">RCPT TO: value.</param> /// <param name="reply">SMTP server reply.</param> /// <exception cref="ArgumentNullException">Is raised when <b>session</b>, <b>to</b> or <b>reply</b> is null reference.</exception> public SMTP_e_RcptTo(SMTP_Session session,SMTP_RcptTo to,SMTP_Reply reply) { if(session == null){ throw new ArgumentNullException("session"); } if(to == null){ throw new ArgumentNullException("from"); } if(reply == null){ throw new ArgumentNullException("reply"); } m_pSession = session; m_pRcptTo = to; m_pReply = reply; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Owner SMTP server session.</param> /// <param name="to">RCPT TO: value.</param> /// <param name="reply">SMTP server reply.</param> /// <exception cref="ArgumentNullException">Is raised when <b>session</b>, <b>to</b> or <b>reply</b> is null reference.</exception> public SMTP_e_RcptTo(SMTP_Session session, SMTP_RcptTo to, SMTP_Reply reply) { if (session == null) { throw new ArgumentNullException("session"); } if (to == null) { throw new ArgumentNullException("from"); } if (reply == null) { throw new ArgumentNullException("reply"); } m_pSession = session; m_pRcptTo = to; m_pReply = reply; }
/// <summary> /// Raises <b>RcptTo</b> event. /// </summary> /// <param name="to">RCPT TO: value.</param> /// <param name="reply">Default SMTP server reply.</param> /// <returns>Returns SMTP server reply what must be sent to the connected client.</returns> private SMTP_Reply OnRcptTo(SMTP_RcptTo to,SMTP_Reply reply) { if(this.RcptTo != null){ SMTP_e_RcptTo eArgs = new SMTP_e_RcptTo(this,to,reply); this.RcptTo(this,eArgs); return eArgs.Reply; } return reply; }
private void RCPT(string cmdText) { // RFC 5321 3.1. if(m_SessionRejected){ WriteLine("503 bad sequence of commands: Session rejected."); return; } // RFC 5321 4.1.4. if(string.IsNullOrEmpty(m_EhloHost)){ WriteLine("503 Bad sequence of commands: send EHLO/HELO first."); return; } // RFC 5321 4.1.4. if(m_pFrom == null){ WriteLine("503 Bad sequence of commands: send 'MAIL FROM:' first."); return; } // RFC 3030 BDAT. if(m_pMessageStream != null){ WriteLine("503 Bad sequence of commands: BDAT command is pending."); return; } /* RFC 5321 4.1.1.3. rcpt = "RCPT TO:" ( "<Postmaster@" Domain ">" / "<Postmaster>" / Forward-path ) [SP Rcpt-parameters] CRLF Rcpt-parameters = esmtp-param *(SP esmtp-param) esmtp-param = esmtp-keyword ["=" esmtp-value] esmtp-keyword = (ALPHA / DIGIT) *(ALPHA / DIGIT / "-") esmtp-value = 1*(%d33-60 / %d62-126) ; any CHAR excluding "=", SP, and control ; characters. If this string is an email address, ; i.e., a Mailbox, then the "xtext" syntax [32] SHOULD be used. Note that, in a departure from the usual rules for local-parts, the "Postmaster" string shown above is treated as case-insensitive. Forward-path = Path Path = "<" [ A-d-l ":" ] Mailbox ">" 4.1.1.11. If the server SMTP does not recognize or cannot implement one or more of the parameters associated with a particular MAIL FROM or RCPT TO command, it will return code 555. */ if(cmdText.ToUpper().StartsWith("TO:")){ // Remove TO: from command text. cmdText = cmdText.Substring(3).Trim(); } else{ WriteLine("501 Syntax error, syntax: \"RCPT TO:\" \"<\" address \">\" [SP Rcpt-parameters] CRLF"); return; } string address = ""; SMTP_DSN_Notify notify = SMTP_DSN_Notify.NotSpecified; string orcpt = null; // Mailbox not between <>. if(!cmdText.StartsWith("<") || cmdText.IndexOf('>') == -1){ WriteLine("501 Syntax error, syntax: \"RCPT TO:\" \"<\" address \">\" [SP Rcpt-parameters] CRLF"); return; } // Parse mailbox. else{ address = cmdText.Substring(1,cmdText.IndexOf('>') - 1).Trim(); cmdText = cmdText.Substring(cmdText.IndexOf('>') + 1).Trim(); } if(address == string.Empty){ WriteLine("501 Syntax error('address' value must be specified), syntax: \"RCPT TO:\" \"<\" address \">\" [SP Rcpt-parameters] CRLF"); return; } #region Parse parameters string[] parameters = string.IsNullOrEmpty(cmdText) ? new string[0] : cmdText.Split(' '); foreach(string parameter in parameters){ string[] name_value = parameter.Split(new char[]{'='},2); // NOTIFY if(this.Server.Extentions.Contains(SMTP_ServiceExtensions.DSN) && name_value[0].ToUpper() == "NOTIFY"){ /* RFC 1891 5.1. notify-esmtp-value = "NEVER" / 1#notify-list-element notify-list-element = "SUCCESS" / "FAILURE" / "DELAY" a. Multiple notify-list-elements, separated by commas, MAY appear in a NOTIFY parameter; however, the NEVER keyword MUST appear by itself. */ if(name_value.Length == 1){ WriteLine("501 Syntax error: NOTIFY parameter value must be specified."); return; } string[] notifyItems = name_value[1].ToUpper().Split(','); foreach(string notifyItem in notifyItems){ if(notifyItem.Trim().ToUpper() == "NEVER"){ notify |= SMTP_DSN_Notify.Never; } else if(notifyItem.Trim().ToUpper() == "SUCCESS"){ notify |= SMTP_DSN_Notify.Success; } else if(notifyItem.Trim().ToUpper() == "FAILURE"){ notify |= SMTP_DSN_Notify.Failure; } else if(notifyItem.Trim().ToUpper() == "DELAY"){ notify |= SMTP_DSN_Notify.Delay; } // Invalid or not supported notify item. else{ WriteLine("501 Syntax error: Not supported NOTIFY parameter value '" + notifyItem + "'."); return; } } } // ORCPT else if(this.Server.Extentions.Contains(SMTP_ServiceExtensions.DSN) && name_value[0].ToUpper() == "ORCPT"){ if(name_value.Length == 1){ WriteLine("501 Syntax error: ORCPT parameter value must be specified."); return; } orcpt = name_value[1].ToUpper(); } // Unsupported parameter. else{ WriteLine("555 Unsupported parameter: " + parameter); } } #endregion // Maximum allowed recipients exceeded. if(m_pTo.Count >= this.Server.MaxRecipients){ WriteLine("452 Too many recipients"); return; } SMTP_RcptTo to = new SMTP_RcptTo(address,notify,orcpt); SMTP_Reply reply = new SMTP_Reply(250,"OK."); reply = OnRcptTo(to,reply); // RCPT accepted. if(reply.ReplyCode < 300){ if(!m_pTo.ContainsKey(address.ToLower())){ m_pTo.Add(address.ToLower(),to); } } WriteLine(reply.ToString()); }
/// <summary> /// Processes and stores message. /// </summary> /// <param name="envelopeID">Envelope ID_(MAIL FROM: ENVID).</param> /// <param name="sender">Mail from.</param> /// <param name="ret">Specifies what parts of message are returned in DSN report.</param> /// <param name="recipients">Message recipients.</param> /// <param name="msgStream">Message stream. Stream position must be there where message begins.</param> /// <param name="e">Event data.</param> /// <exception cref="ArgumentNullException">Is raised when <b>recipients</b> or <b>msgStream</b> is nulll reference.</exception> public void ProcessAndStoreMessage(string envelopeID,string sender,SMTP_DSN_Ret ret,SMTP_RcptTo[] recipients,Stream msgStream,SMTP_e_MessageStored e) { if(recipients == null){ throw new ArgumentNullException("recipients"); } if(msgStream == null){ throw new ArgumentNullException("msgStream"); } /* Message processing. *) Message filters. *) Global message rules. *) Process recipients. */ List<SMTP_RcptTo> dsn_Delivered = new List<SMTP_RcptTo>(); string[] to = new string[recipients.Length]; for(int i=0;i<to.Length;i++){ to[i] = recipients[i].Mailbox; } #region Global Filtering stuff //--- Filter message -----------------------------------------------// Stream filteredMsgStream = msgStream; DataView dvFilters = m_pApi.GetFilters(); dvFilters.RowFilter = "Enabled=true AND Type='ISmtpMessageFilter'"; dvFilters.Sort = "Cost"; foreach(DataRowView drViewFilter in dvFilters){ try{ filteredMsgStream.Position = 0; string assemblyFile = API_Utlis.PathFix(drViewFilter.Row["Assembly"].ToString()); // File is without path probably, try to load it from filters folder if(!File.Exists(assemblyFile)){ assemblyFile = API_Utlis.PathFix(m_pOwnerServer.StartupPath + "\\Filters\\" + assemblyFile); } Assembly ass = Assembly.LoadFrom(assemblyFile); Type tp = ass.GetType(drViewFilter.Row["ClassName"].ToString()); object filterInstance = Activator.CreateInstance(tp); ISmtpMessageFilter filter = (ISmtpMessageFilter)filterInstance; string errorText = ""; SMTP_Session session = null; if(e != null){ session = e.Session; } FilterResult result = filter.Filter(filteredMsgStream,out filteredMsgStream,sender,to,m_pApi,session,out errorText); if(result == FilterResult.DontStore){ // Just skip messge, act as message is stored e.Reply = new SMTP_Reply(552,"Requested mail action aborted: Message discarded by server filter."); return; } else if(result == FilterResult.Error){ if(e != null){ e.Reply = new SMTP_Reply(552,"Requested mail action aborted: " + errorText); } else{ // NOTE: 26.01.2006 - e maybe null if that method is called server internally and no smtp session. } return; } // Filter didn't return message stream if(filteredMsgStream == null){ e.Reply = new SMTP_Reply(552,"Requested mail action aborted: Message discarded by server filter."); return; } } catch(Exception x){ // Filtering failed, log error and allow message through. OnError(x); } } //---------------------------------------------------------------// #endregion #region Global Message Rules filteredMsgStream.Position = 0; Mail_Message mime = null; try{ mime = Mail_Message.ParseFromStream(filteredMsgStream); } // Invalid message syntax, block such message. catch{ e.Reply = new SMTP_Reply(552,"Requested mail action aborted: Message has invalid structure/syntax."); try{ if(!Directory.Exists(this.MailStorePath + "Unparseable")){ Directory.CreateDirectory(this.MailStorePath + "Unparseable"); } using(FileStream fs = File.Create(this.MailStorePath + "Unparseable\\" + Guid.NewGuid().ToString().Replace("-","") + ".eml")){ filteredMsgStream.Position = 0; Net_Utils.StreamCopy(filteredMsgStream,fs,32000); } } catch{ } return; } //--- Check Global Message Rules --------------------------------------------------------------// bool deleteMessage = false; string storeFolder = "Inbox"; string smtpErrorText = null; // Loop rules foreach(DataRowView drV_Rule in m_pApi.GetGlobalMessageRules()){ // Reset stream position filteredMsgStream.Position = 0; if(Convert.ToBoolean(drV_Rule["Enabled"])){ string ruleID = drV_Rule["RuleID"].ToString(); GlobalMessageRule_CheckNextRule_enum checkNextIf = (GlobalMessageRule_CheckNextRule_enum)(int)drV_Rule["CheckNextRuleIf"]; string matchExpression = drV_Rule["MatchExpression"].ToString(); // e may be null if server internal method call and no actual session ! SMTP_Session session = null; if(e != null){ session = e.Session; } GlobalMessageRuleProcessor ruleEngine = new GlobalMessageRuleProcessor(); bool matches = ruleEngine.Match(matchExpression,sender,to,session,mime,(int)filteredMsgStream.Length); if(matches){ // Do actions GlobalMessageRuleActionResult result = ruleEngine.DoActions( m_pApi.GetGlobalMessageRuleActions(ruleID), this, filteredMsgStream, sender, to ); if(result.DeleteMessage){ deleteMessage = true; } if(result.StoreFolder != null){ storeFolder = result.StoreFolder; } if(result.ErrorText != null){ smtpErrorText = result.ErrorText; } } //--- See if we must check next rule -------------------------------------------------// if(checkNextIf == GlobalMessageRule_CheckNextRule_enum.Always){ // Do nothing } else if(checkNextIf == GlobalMessageRule_CheckNextRule_enum.IfMatches && !matches){ break; } else if(checkNextIf == GlobalMessageRule_CheckNextRule_enum.IfNotMatches && matches){ break; } //------------------------------------------------------------------------------------// } } // Return error to connected client if(smtpErrorText != null){ e.Reply = new SMTP_Reply(552,"Requested mail action aborted: " + smtpErrorText); return; } // Just don't store message if(deleteMessage){ return; } // Reset stream position filteredMsgStream.Position = 0; //--- End of Global Rules -------------------------------------------------------------------// #endregion #region Process recipients HashSet<string> processedItems = new HashSet<string>(); Queue<SMTP_RcptTo> recipientsQueue = new Queue<SMTP_RcptTo>(); // Queue current recipients for processing. foreach(SMTP_RcptTo recipient in recipients){ recipientsQueue.Enqueue(recipient); } while(recipientsQueue.Count > 0){ /* Process order *) Local user *) Local address *) Local mailing list address *) Route *) Relay */ SMTP_RcptTo recipient = recipientsQueue.Dequeue(); // Check if we already have processed this item. Skip dublicate items. // This method also avoids loops when 2 recipients reference each other. if(processedItems.Contains(recipient.Mailbox)){ continue; } processedItems.Add(recipient.Mailbox); #region Local user if(recipient.Mailbox.IndexOf('@') == -1 && m_pApi.UserExists(recipient.Mailbox)){ // Add user to processed list. processedItems.Add(recipient.Mailbox); // Delivery status notification(DSN) requested to this user. if((recipient.Notify & SMTP_DSN_Notify.Success) != 0){ dsn_Delivered.Add(recipient); } ProcessUserMsg(sender,recipient.Mailbox,recipient.Mailbox,storeFolder,filteredMsgStream,e); continue; } #endregion #region Local address string localUser = m_pApi.MapUser(recipient.Mailbox); if(localUser != null){ // Add user to processed list. processedItems.Add(localUser); // Delivery status notification(DSN) requested to this user. if((recipient.Notify & SMTP_DSN_Notify.Success) != 0){ dsn_Delivered.Add(recipient); } ProcessUserMsg(sender,recipient.Mailbox,localUser,storeFolder,filteredMsgStream,e); } #endregion #region Mailing list address else if(m_pApi.MailingListExists(recipient.Mailbox)){ // Delivery status notification(DSN) requested to this user. if((recipient.Notify & SMTP_DSN_Notify.Success) != 0){ dsn_Delivered.Add(recipient); } Queue<string> processQueue = new Queue<string>(); processQueue.Enqueue(recipient.Mailbox); // Loop while there are mailing lists or nested mailing list available while(processQueue.Count > 0){ string mailingList = processQueue.Dequeue(); // Process mailing list members foreach(DataRowView drV in m_pApi.GetMailingListAddresses(mailingList)){ string member = drV["Address"].ToString(); // Member is asteric pattern matching server emails if(member.IndexOf('*') > -1){ DataView dvServerAddresses = m_pApi.GetUserAddresses(""); foreach(DataRowView drvServerAddress in dvServerAddresses){ string serverAddress = drvServerAddress["Address"].ToString(); if(SCore.IsAstericMatch(member,serverAddress)){ recipientsQueue.Enqueue(new SMTP_RcptTo(serverAddress,SMTP_DSN_Notify.NotSpecified,null)); } } } // Member is user or group, not email address else if(member.IndexOf('@') == -1){ // Member is group, replace with actual users if(m_pApi.GroupExists(member)){ foreach(string user in m_pApi.GetGroupUsers(member)){ recipientsQueue.Enqueue(new SMTP_RcptTo(user,SMTP_DSN_Notify.NotSpecified,null)); } } // Member is user else if(m_pApi.UserExists(member)){ recipientsQueue.Enqueue(new SMTP_RcptTo(member,SMTP_DSN_Notify.NotSpecified,null)); } // Unknown member, skip it. else{ } } // Member is nested mailing list else if(m_pApi.MailingListExists(member)){ processQueue.Enqueue(member); } // Member is normal email address else{ recipientsQueue.Enqueue(new SMTP_RcptTo(member,SMTP_DSN_Notify.NotSpecified,null)); } } } } #endregion else{ bool isRouted = false; #region Check Routing foreach(DataRowView drRoute in m_pApi.GetRoutes()){ // We have matching route if(Convert.ToBoolean(drRoute["Enabled"]) && SCore.IsAstericMatch(drRoute["Pattern"].ToString(),recipient.Mailbox)){ string description = drRoute["Action"].ToString(); RouteAction_enum action = (RouteAction_enum)Convert.ToInt32(drRoute["Action"]); byte[] actionData = (byte[])drRoute["ActionData"]; #region RouteToEmail if(action == RouteAction_enum.RouteToEmail){ XmlTable table = new XmlTable("ActionData"); table.Parse(actionData); // Add email to process queue. recipientsQueue.Enqueue(new SMTP_RcptTo(table.GetValue("EmailAddress"),SMTP_DSN_Notify.NotSpecified,null)); // Log if(e != null){ e.Session.LogAddText("Route '[" + description + "]: " + drRoute["Pattern"].ToString() + "' routed to email '" + table.GetValue("EmailAddress") + "'."); } } #endregion #region RouteToHost else if(action == RouteAction_enum.RouteToHost){ XmlTable table = new XmlTable("ActionData"); table.Parse(actionData); msgStream.Position = 0; // Route didn't match, so we have relay message. this.RelayServer.StoreRelayMessage( Guid.NewGuid().ToString(), envelopeID, msgStream, HostEndPoint.Parse(table.GetValue("Host") + ":" + table.GetValue("Port")), sender, recipient.Mailbox, recipient.ORCPT, recipient.Notify, ret ); // Log if(e != null){ e.Session.LogAddText("Route '[" + description + "]: " + drRoute["Pattern"].ToString() + "' routed to host '" + table.GetValue("Host") + ":" + table.GetValue("Port") + "'."); } } #endregion #region RouteToMailbox else if(action == RouteAction_enum.RouteToMailbox){ XmlTable table = new XmlTable("ActionData"); table.Parse(actionData); ProcessUserMsg(sender,recipient.Mailbox,table.GetValue("Mailbox"),storeFolder,filteredMsgStream,e); // Log if(e != null){ e.Session.LogAddText("Route '[" + description + "]: " + drRoute["Pattern"].ToString() + "' routed to user '" + table.GetValue("Mailbox") + "'."); } } #endregion isRouted = true; break; } } #endregion // Route didn't match, so we have relay message. if(!isRouted){ filteredMsgStream.Position = 0; this.RelayServer.StoreRelayMessage( Guid.NewGuid().ToString(), envelopeID, filteredMsgStream, null, sender, recipient.Mailbox, recipient.ORCPT, recipient.Notify, ret ); } } } #endregion #region DSN "delivered" // Send DSN for requested recipients. if(dsn_Delivered.Count > 0 && !string.IsNullOrEmpty(sender)){ try{ string dsn_to = ""; for(int i=0;i<dsn_Delivered.Count;i++){ if(i == (dsn_Delivered.Count - 1)){ dsn_to += dsn_Delivered[i].Mailbox; } else{ dsn_to += dsn_Delivered[i].Mailbox + "; "; } } string reportingMTA = ""; if(e != null && !string.IsNullOrEmpty(e.Session.LocalHostName)){ reportingMTA = e.Session.LocalHostName; } else{ reportingMTA = System.Net.Dns.GetHostName(); } ServerReturnMessage messageTemplate = null; if(messageTemplate == null){ string bodyRtf = "" + "{\\rtf1\\ansi\\ansicpg1257\\deff0\\deflang1061{\\fonttbl{\\f0\\froman\\fcharset0 Times New Roman;}{\\f1\froman\\fcharset186{\\*\\fname Times New Roman;}Times New Roman Baltic;}{\\f2\fswiss\\fcharset186{\\*\\fname Arial;}Arial Baltic;}}\r\n" + "{\\colortbl ;\\red0\\green128\\blue0;\\red128\\green128\\blue128;}\r\n" + "{\\*\\generator Msftedit 5.41.21.2508;}\\viewkind4\\uc1\\pard\\sb100\\sa100\\lang1033\\f0\\fs24\\par\r\n" + "Your message WAS SUCCESSFULLY DELIVERED to:\\line\\lang1061\\f1\\tab\\cf1\\lang1033\\b\\f0 " + dsn_to + "\\line\\cf0\\b0 and you explicitly requested a delivery status notification on success.\\par\\par\r\n" + "\\cf2 Your original message\\lang1061\\f1 /header\\lang1033\\f0 is attached to this e-mail\\lang1061\\f1 .\\lang1033\\f0\\par\\r\\n" + "\\cf0\\line\\par\r\n" + "\\pard\\lang1061\\f2\\fs20\\par\r\n" + "}\r\n"; messageTemplate = new ServerReturnMessage("DSN SUCCESSFULLY DELIVERED: " + mime.Subject,bodyRtf); } string rtf = messageTemplate.BodyTextRtf; Mail_Message dsnMsg = new Mail_Message(); dsnMsg.MimeVersion = "1.0"; dsnMsg.Date = DateTime.Now; dsnMsg.From = new Mail_t_MailboxList(); dsnMsg.From.Add(new Mail_t_Mailbox("Mail Delivery Subsystem","postmaster@local")); dsnMsg.To = new Mail_t_AddressList(); dsnMsg.To.Add(new Mail_t_Mailbox(null,sender)); dsnMsg.Subject = messageTemplate.Subject; //--- multipart/report ------------------------------------------------------------------------------------------------- MIME_h_ContentType contentType_multipartReport = new MIME_h_ContentType(MIME_MediaTypes.Multipart.report); contentType_multipartReport.Parameters["report-type"] = "delivery-status"; contentType_multipartReport.Param_Boundary = Guid.NewGuid().ToString().Replace('-','.'); MIME_b_MultipartReport multipartReport = new MIME_b_MultipartReport(contentType_multipartReport); dsnMsg.Body = multipartReport; //--- multipart/alternative ----------------------------------------------------------------------------------------- MIME_Entity entity_multipart_alternative = new MIME_Entity(); MIME_h_ContentType contentType_multipartAlternative = new MIME_h_ContentType(MIME_MediaTypes.Multipart.alternative); contentType_multipartAlternative.Param_Boundary = Guid.NewGuid().ToString().Replace('-','.'); MIME_b_MultipartAlternative multipartAlternative = new MIME_b_MultipartAlternative(contentType_multipartAlternative); entity_multipart_alternative.Body = multipartAlternative; multipartReport.BodyParts.Add(entity_multipart_alternative); //--- text/plain --------------------------------------------------------------------------------------------------- MIME_Entity entity_text_plain = new MIME_Entity(); MIME_b_Text text_plain = new MIME_b_Text(MIME_MediaTypes.Text.plain); entity_text_plain.Body = text_plain; text_plain.SetText(MIME_TransferEncodings.QuotedPrintable,Encoding.UTF8,SCore.RtfToText(rtf)); multipartAlternative.BodyParts.Add(entity_text_plain); //--- text/html ----------------------------------------------------------------------------------------------------- MIME_Entity entity_text_html = new MIME_Entity(); MIME_b_Text text_html = new MIME_b_Text(MIME_MediaTypes.Text.html); entity_text_html.Body = text_html; text_html.SetText(MIME_TransferEncodings.QuotedPrintable,Encoding.UTF8,SCore.RtfToHtml(rtf)); multipartAlternative.BodyParts.Add(entity_text_html); //--- message/delivery-status MIME_Entity entity_message_deliveryStatus = new MIME_Entity(); MIME_b_MessageDeliveryStatus body_message_deliveryStatus = new MIME_b_MessageDeliveryStatus(); entity_message_deliveryStatus.Body = body_message_deliveryStatus; multipartReport.BodyParts.Add(entity_message_deliveryStatus); //--- per-message-fields ---------------------------------------------------------------------------- MIME_h_Collection messageFields = body_message_deliveryStatus.MessageFields; if(!string.IsNullOrEmpty(envelopeID)){ messageFields.Add(new MIME_h_Unstructured("Original-Envelope-Id",envelopeID)); } messageFields.Add(new MIME_h_Unstructured("Arrival-Date",MIME_Utils.DateTimeToRfc2822(DateTime.Now))); if(e != null && !string.IsNullOrEmpty(e.Session.EhloHost)){ messageFields.Add(new MIME_h_Unstructured("Received-From-MTA","dns;" + e.Session.EhloHost)); } messageFields.Add(new MIME_h_Unstructured("Reporting-MTA","dns;" + reportingMTA)); //--------------------------------------------------------------------------------------------------- foreach(SMTP_RcptTo r in dsn_Delivered){ //--- per-recipient-fields -------------------------------------------------------------------------- MIME_h_Collection recipientFields = new MIME_h_Collection(new MIME_h_Provider()); if(r.ORCPT != null){ recipientFields.Add(new MIME_h_Unstructured("Original-Recipient",r.ORCPT)); } recipientFields.Add(new MIME_h_Unstructured("Final-Recipient","rfc822;" + r.Mailbox)); recipientFields.Add(new MIME_h_Unstructured("Action","delivered")); recipientFields.Add(new MIME_h_Unstructured("Status","2.0.0")); body_message_deliveryStatus.RecipientBlocks.Add(recipientFields); //--------------------------------------------------------------------------------------------------- } //--- message/rfc822 if(mime != null){ MIME_Entity entity_message_rfc822 = new MIME_Entity(); MIME_b_MessageRfc822 body_message_rfc822 = new MIME_b_MessageRfc822(); entity_message_rfc822.Body = body_message_rfc822; if(ret == SMTP_DSN_Ret.FullMessage){ body_message_rfc822.Message = mime; } else{ MemoryStream ms = new MemoryStream(); mime.Header.ToStream(ms,null,null); ms.Position = 0; body_message_rfc822.Message = Mail_Message.ParseFromStream(ms); } multipartReport.BodyParts.Add(entity_message_rfc822); } using(MemoryStream strm = new MemoryStream()){ dsnMsg.ToStream(strm,new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q,Encoding.UTF8),Encoding.UTF8); ProcessAndStoreMessage("",new string[]{sender},strm,null); } } catch(Exception x){ Error.DumpError(this.Name,x); } } #endregion }