Example #1
0
        /// <summary>
        /// Sends deliver-status-notification 'success' message.
        /// </summary>
        /// <param name="session">Relay session.</param>
        private void Send_DSN_Relayed(Relay_Session session)
        {
            if (session == null)
            {
                return;
            }

            try{
                // No sender specified, can't send notify, just skip it.
                if (string.IsNullOrEmpty(session.From))
                {
                    return;
                }

                RelayMessageInfo relayInfo = (RelayMessageInfo)session.QueueTag;

                // Send DSN only if user has specified "success".
                if ((relayInfo.DSN_Notify & SMTP_DSN_Notify.Success) == 0)
                {
                    return;
                }

                session.MessageStream.Position = 0;
                Mail_Message          relayMessage = Mail_Message.ParseFromStream(session.MessageStream);
                RelayVariablesManager variablesMgr = new RelayVariablesManager(this, session, "", relayMessage);

                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 RELAYED to:\\line\\lang1061\\f1\\tab\\cf1\\lang1033\\b\\f0 <" + session.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 RELAYED: <#message.header[\"Subject:\"]>", bodyRtf);
                }

                string rtf = variablesMgr.Process(messageTemplate.BodyTextRtf);

                Mail_Message dsnMessage = DeliveryStatusNotification.CreateDsnMessage(
                    session.From,
                    variablesMgr.Process(messageTemplate.Subject),
                    rtf,
                    relayInfo.EnvelopeID,
                    relayInfo.Date,
                    null,
                    (session.IsConnected && string.IsNullOrEmpty(session.LocalHostName)) ? session.LocalEndPoint.Address.ToString() : session.LocalHostName,
                    relayInfo.OriginalRecipient,
                    session.To,
                    "relayed",
                    "200 OK",
                    session.RemoteHostName,
                    DateTime.MinValue,
                    DateTime.MinValue,
                    (relayInfo.DSN_Ret == SMTP_DSN_Ret.NotSpecified) ? SMTP_DSN_Ret.Headers : relayInfo.DSN_Ret,
                    relayMessage
                    );

                using (MemoryStream strm = new MemoryStream()){
                    dsnMessage.ToStream(strm, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                    m_pVirtualServer.ProcessAndStoreMessage("", new string[] { session.From }, strm, null);
                }

                relayMessage.Dispose();
                dsnMessage.Dispose();
            }
            catch (Exception x) {
                LumiSoft.MailServer.Error.DumpError(m_pVirtualServer.Name, x);
            }
        }
Example #2
0
        /// <summary>
        /// Creates and sends "Delayed delivery notify" to message sender.
        /// </summary>
        /// <param name="session">Relay_Session.</param>
        /// <param name="error">Error happened.</param>
        private void Send_DSN_Delayed(Relay_Session session, string error)
        {
            try{
                // No sender specified, can't send notify, just skip it.
                if (string.IsNullOrEmpty(session.From))
                {
                    return;
                }

                RelayMessageInfo relayInfo = (RelayMessageInfo)session.QueueTag;

                // Send DSN only if user has not specified at all or has specified "delay".
                if (relayInfo.DSN_Notify != SMTP_DSN_Notify.NotSpecified && (relayInfo.DSN_Notify & SMTP_DSN_Notify.Delay) == 0)
                {
                    return;
                }

                session.MessageStream.Position = 0;
                Mail_Message          relayMessage = Mail_Message.ParseFromStream(session.MessageStream);
                RelayVariablesManager variablesMgr = new RelayVariablesManager(this, session, error, relayMessage);

                ServerReturnMessage messageTemplate = this.DelayedDeliveryMessage;
                if (messageTemplate == null)
                {
                    string bodyRtf = "" +
                                     "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Verdana;}{\\f1\\fnil\\fcharset186 Verdana;}{\\f2\\fswiss\\fcharset186{\\*\\fname Arial;}Arial Baltic;}{\\f3\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n" +
                                     "{\\colortbl ;\\red0\\green64\\blue128;\\red255\\green0\\blue0;\\red0\\green128\\blue0;}\r\n" +
                                     "\\viewkind4\\uc1\\pard\\f0\\fs20 This e-mail is generated by the Server(\\cf1 <#relay.hostname>\\cf0 )  to notify you, \\par\r\n" +
                                     "\\lang1061\\f1 that \\lang1033\\f0 your message to \\cf1 <#relay.to>\\cf0  dated \\b\\fs16 <#message.header[\"Date:\"]>\\b0  \\fs20 could not be sent at the first attempt.\\par\r\n" +
                                     "\\par\r\n" +
                                     "Recipient \\i <#relay.to>'\\i0 s Server (\\cf1 <#relay.session_hostname>\\cf0 ) returned the following response: \\cf2 <#relay.error>\\cf0\\par\r\n" +
                                     "\\par\r\n" +
                                     "\\par\r\n" +
                                     "Please note Server will attempt to deliver this message for \\b <#relay.undelivered_after>\\b0  hours.\\par\r\n" +
                                     "\\par\r\n" +
                                     "--------\\par\r\n" +
                                     "\\par\r\n" +
                                     "Your original message is attached to this e-mail (\\b data.eml\\b0 )\\par\r\n" +
                                     "\\par\r\n" +
                                     "\\fs16 The tracking number for this message is \\cf3 <#relay.session_messageid>\\cf0\\fs20\\par\r\n" +
                                     "\\lang1061\\f2\\par\r\n" +
                                     "\\pard\\lang1033\\f3\\fs17\\par\r\n" +
                                     "}\r\n";

                    messageTemplate = new ServerReturnMessage("Delayed delivery notice: <#message.header[\"Subject:\"]>", bodyRtf);
                }

                string rtf = variablesMgr.Process(messageTemplate.BodyTextRtf);

                Mail_Message dsnMessage = DeliveryStatusNotification.CreateDsnMessage(
                    session.From,
                    variablesMgr.Process(messageTemplate.Subject),
                    rtf,
                    relayInfo.EnvelopeID,
                    relayInfo.Date,
                    null,
                    (session.IsConnected && string.IsNullOrEmpty(session.LocalHostName)) ? session.LocalEndPoint.Address.ToString() : session.LocalHostName,
                    relayInfo.OriginalRecipient,
                    session.To,
                    "delayed",
                    error,
                    session.RemoteHostName,
                    DateTime.Now,
                    relayInfo.Date.AddMinutes(this.UndeliveredAfter),
                    (relayInfo.DSN_Ret == SMTP_DSN_Ret.NotSpecified) ? SMTP_DSN_Ret.FullMessage : relayInfo.DSN_Ret,
                    relayMessage
                    );

                using (MemoryStream strm = new MemoryStream()){
                    dsnMessage.ToStream(strm, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                    m_pVirtualServer.ProcessAndStoreMessage("", new string[] { session.From }, strm, null);
                }

                relayMessage.Dispose();
                dsnMessage.Dispose();
            }
            catch (Exception x) {
                LumiSoft.MailServer.Error.DumpError(m_pVirtualServer.Name, x);
            }
        }
Example #3
0
        /// <summary>
        /// Creates and sends "Delayed delivery notify" to message sender.
        /// </summary>
        /// <param name="session">Relay_Session.</param>
        /// <param name="error">Error happened.</param>
        private void Send_DSN_Delayed(Relay_Session session,string error)
        {
            try{
                // No sender specified, can't send notify, just skip it.
                if(string.IsNullOrEmpty(session.From)){
                    return;
                }

                RelayMessageInfo relayInfo = (RelayMessageInfo)session.QueueTag;

                // Send DSN only if user has not specified at all or has specified "delay".
                if(relayInfo.DSN_Notify != SMTP_DSN_Notify.NotSpecified && (relayInfo.DSN_Notify & SMTP_DSN_Notify.Delay) == 0){
                    return;
                }

                session.MessageStream.Position = 0;
                Mail_Message relayMessage = Mail_Message.ParseFromStream(session.MessageStream);
                RelayVariablesManager variablesMgr = new RelayVariablesManager(this,session,error,relayMessage);

                ServerReturnMessage messageTemplate = this.DelayedDeliveryMessage;
                if(messageTemplate == null){
                    string bodyRtf = "" +
                    "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Verdana;}{\\f1\\fnil\\fcharset186 Verdana;}{\\f2\\fswiss\\fcharset186{\\*\\fname Arial;}Arial Baltic;}{\\f3\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n" +
                    "{\\colortbl ;\\red0\\green64\\blue128;\\red255\\green0\\blue0;\\red0\\green128\\blue0;}\r\n" +
                    "\\viewkind4\\uc1\\pard\\f0\\fs20 This e-mail is generated by the Server(\\cf1 <#relay.hostname>\\cf0 )  to notify you, \\par\r\n" +
                    "\\lang1061\\f1 that \\lang1033\\f0 your message to \\cf1 <#relay.to>\\cf0  dated \\b\\fs16 <#message.header[\"Date:\"]>\\b0  \\fs20 could not be sent at the first attempt.\\par\r\n" +
                    "\\par\r\n" +
                    "Recipient \\i <#relay.to>'\\i0 s Server (\\cf1 <#relay.session_hostname>\\cf0 ) returned the following response: \\cf2 <#relay.error>\\cf0\\par\r\n" +
                    "\\par\r\n" +
                    "\\par\r\n" +
                    "Please note Server will attempt to deliver this message for \\b <#relay.undelivered_after>\\b0  hours.\\par\r\n" +
                    "\\par\r\n" +
                    "--------\\par\r\n" +
                    "\\par\r\n" +
                    "Your original message is attached to this e-mail (\\b data.eml\\b0 )\\par\r\n" +
                    "\\par\r\n" +
                    "\\fs16 The tracking number for this message is \\cf3 <#relay.session_messageid>\\cf0\\fs20\\par\r\n" +
                    "\\lang1061\\f2\\par\r\n" +
                    "\\pard\\lang1033\\f3\\fs17\\par\r\n" +
                    "}\r\n";

                    messageTemplate = new ServerReturnMessage("Delayed delivery notice: <#message.header[\"Subject:\"]>",bodyRtf);
                }

                string rtf = variablesMgr.Process(messageTemplate.BodyTextRtf);

                Mail_Message dsnMessage = DeliveryStatusNotification.CreateDsnMessage(
                    session.From,
                    variablesMgr.Process(messageTemplate.Subject),
                    rtf,
                    relayInfo.EnvelopeID,
                    relayInfo.Date,
                    null, 
                    (session.IsConnected && string.IsNullOrEmpty(session.LocalHostName)) ? session.LocalEndPoint.Address.ToString() : session.LocalHostName,
                    relayInfo.OriginalRecipient,
                    session.To,
                    "delayed",
                    error,
                    session.RemoteHostName,
                    DateTime.Now,
                    relayInfo.Date.AddMinutes(this.UndeliveredAfter),
                    (relayInfo.DSN_Ret == SMTP_DSN_Ret.NotSpecified) ? SMTP_DSN_Ret.FullMessage : relayInfo.DSN_Ret,
                    relayMessage
                );

				using(MemoryStream strm = new MemoryStream()){
					dsnMessage.ToStream(strm,new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q,Encoding.UTF8),Encoding.UTF8);
					m_pVirtualServer.ProcessAndStoreMessage("",new string[]{session.From},strm,null);
				}

                relayMessage.Dispose();
                dsnMessage.Dispose();
            }            
            catch(Exception x){
                LumiSoft.MailServer.Error.DumpError(m_pVirtualServer.Name,x);
            }
        }
Example #4
0
        /// <summary>
        /// Sends deliver-status-notification 'success' message.
        /// </summary>
        /// <param name="session">Relay session.</param>
        private void Send_DSN_Relayed(Relay_Session session)
        {
            if(session == null){
                return;
            }

            try{
                // No sender specified, can't send notify, just skip it.
                if(string.IsNullOrEmpty(session.From)){
                    return;
                }

                RelayMessageInfo relayInfo = (RelayMessageInfo)session.QueueTag;

                // Send DSN only if user has specified "success".
                if((relayInfo.DSN_Notify & SMTP_DSN_Notify.Success) == 0){
                    return;
                }

                session.MessageStream.Position = 0;
                Mail_Message relayMessage = Mail_Message.ParseFromStream(session.MessageStream);
                RelayVariablesManager variablesMgr = new RelayVariablesManager(this,session,"",relayMessage);

                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 RELAYED to:\\line\\lang1061\\f1\\tab\\cf1\\lang1033\\b\\f0 <" + session.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 RELAYED: <#message.header[\"Subject:\"]>",bodyRtf);
                }

                string rtf = variablesMgr.Process(messageTemplate.BodyTextRtf);

                Mail_Message dsnMessage = DeliveryStatusNotification.CreateDsnMessage(
                    session.From,
                    variablesMgr.Process(messageTemplate.Subject),
                    rtf,
                    relayInfo.EnvelopeID,
                    relayInfo.Date,
                    null, 
                    (session.IsConnected && string.IsNullOrEmpty(session.LocalHostName)) ? session.LocalEndPoint.Address.ToString() : session.LocalHostName,
                    relayInfo.OriginalRecipient,
                    session.To,
                    "relayed",
                    "200 OK",
                    session.RemoteHostName,
                    DateTime.MinValue,
                    DateTime.MinValue,
                    (relayInfo.DSN_Ret == SMTP_DSN_Ret.NotSpecified) ? SMTP_DSN_Ret.Headers : relayInfo.DSN_Ret,
                    relayMessage
                );

				using(MemoryStream strm = new MemoryStream()){
					dsnMessage.ToStream(strm,new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q,Encoding.UTF8),Encoding.UTF8);
					m_pVirtualServer.ProcessAndStoreMessage("",new string[]{session.From},strm,null);
				}

                relayMessage.Dispose();
                dsnMessage.Dispose();
            }
            catch(Exception x){
                LumiSoft.MailServer.Error.DumpError(m_pVirtualServer.Name,x);
            }
        }
        /// <summary>
        /// Creates undelivered warning for user and places it to relay folder.
        /// </summary>
        /// <param name="relayInfo">Relay info</param>
        /// <param name="error">SMTP returned error text.</param>
        /// <param name="file">Messsage file.</param>
        private void MakeUndeliveredWarning(RelayInfo relayInfo,string error,Stream file)
        {
            try{
                // If sender isn't specified, we can't send warning to sender.
                // Just skip warning sending.
                if(relayInfo.From.Length == 0){
                    return;
                }

                file.Position = relayInfo.MessageStartPos;
                RelayVariablesManager variablesMgr = new RelayVariablesManager(this,error,file);
                file.Position = relayInfo.MessageStartPos;

                ServerReturnMessage messageTemplate = m_pRelayServer.UndeliveredMessage;
                if(messageTemplate == null){
                    string bodyRtf = "" +
                    "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Verdana;}{\\f1\\fnil\\fcharset186 Verdana;}{\\f2\\fswiss\\fcharset186{\\*\\fname Arial;}Arial Baltic;}{\\f3\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n" +
                    "{\\colortbl ;\\red0\\green64\\blue128;\\red255\\green0\\blue0;\\red0\\green128\\blue0;}\r\n" +
                    "\\viewkind4\\uc1\\pard\\f0\\fs20 This e-mail is generated by the Server(\\cf1 <#relay.hostname>\\cf0 )  to notify you, \\par\r\n" +
                    "\\lang1061\\f1 that \\lang1033\\f0 your message to \\cf1 <#relay.to>\\cf0  dated \\b\\fs16 <#message.header[\"Date:\"]>\\b0  \\fs20 could not be sent at the first attempt.\\par\r\n" +
                    "\\par\r\n" +
                    "Recipient \\i <#relay.to>'\\i0 s Server (\\cf1 <#relay.session_hostname>\\cf0 ) returned the following response: \\cf2 <#relay.error>\\cf0\\par\r\n" +
                    "\\par\r\n" +
                    "\\par\r\n" +
                    "Please note Server will attempt to deliver this message for \\b <#relay.undelivered_after>\\b0  hours.\\par\r\n" +
                    "\\par\r\n" +
                    "--------\\par\r\n" +
                    "\\par\r\n" +
                    "Your original message is attached to this e-mail (\\b data.eml\\b0 )\\par\r\n" +
                    "\\par\r\n" +
                    "\\fs16 The tracking number for this message is \\cf3 <#relay.session_messageid>\\cf0\\fs20\\par\r\n" +
                    "\\lang1061\\f2\\par\r\n" +
                    "\\pard\\lang1033\\f3\\fs17\\par\r\n" +
                    "}\r\n";

                    messageTemplate = new ServerReturnMessage("Delayed delivery notice: <#message.header[\"Subject:\"]>",bodyRtf);
                }

                // Make new message
                Mime m = new Mime();
                MimeEntity mainEntity = m.MainEntity;
                // Force to create From: header field
                mainEntity.From = new AddressList();
                mainEntity.From.Add(new MailboxAddress("postmaster"));
                // Force to create To: header field
                mainEntity.To = new AddressList();
                mainEntity.To.Add(new MailboxAddress(relayInfo.From));
                mainEntity.Subject = variablesMgr.Process(messageTemplate.Subject);
                mainEntity.ContentType = MediaType_enum.Multipart_mixed;

                string rtf = variablesMgr.Process(messageTemplate.BodyTextRtf);

                MimeEntity multipartAlternativeEntity = mainEntity.ChildEntities.Add();
                multipartAlternativeEntity.ContentType = MediaType_enum.Multipart_alternative;

                MimeEntity textEntity = multipartAlternativeEntity.ChildEntities.Add();
                textEntity.ContentType = MediaType_enum.Text_plain;
                textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                textEntity.DataText = SCore.RtfToText(rtf);

                MimeEntity htmlEntity = multipartAlternativeEntity.ChildEntities.Add();
                htmlEntity.ContentType = MediaType_enum.Text_html;
                htmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable;
                htmlEntity.DataText = SCore.RtfToHtml(rtf);

                MimeEntity attachmentEntity = mainEntity.ChildEntities.Add();
                attachmentEntity.ContentType = MediaType_enum.Application_octet_stream;
                attachmentEntity.ContentDisposition = ContentDisposition_enum.Attachment;
                attachmentEntity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64;
                attachmentEntity.ContentDisposition_FileName = "data.eml";
                attachmentEntity.DataFromStream(file);

                using(MemoryStream strm = new MemoryStream()){
                    m.ToStream(strm);
                    m_pRelayServer.VirtualServer.ProcessAndStoreMessage("",new string[]{relayInfo.From},strm,null);
                }
            }
            catch(Exception x){
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }