/// <summary>
    /// This method called when the page is loaded into the browser. This method requests input stream and parses it to get message counts.
    /// </summary>
    /// <param name="sender">object, which invoked this method</param>
    /// <param name="e">EventArgs, which specifies arguments specific to this method</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        System.IO.Stream stream = Request.InputStream;

        this.receivedDeliveryStatusFilePath = ConfigurationManager.AppSettings["ReceivedDeliveryStatusFilePath"];
        if (string.IsNullOrEmpty(this.receivedDeliveryStatusFilePath))
        {
            this.receivedDeliveryStatusFilePath = "~\\DeliveryStatus.txt";
        }

        string count = ConfigurationManager.AppSettings["NumberOfDeliveryStatusToStore"];

        if (!string.IsNullOrEmpty(count))
        {
            this.numberOfDeliveryStatusToStore = Convert.ToInt32(count);
        }

        if (null != stream)
        {
            byte[] bytes = new byte[stream.Length];
            stream.Position = 0;
            stream.Read(bytes, 0, (int)stream.Length);
            string responseData = Encoding.ASCII.GetString(bytes);

            JavaScriptSerializer       serializeObject = new JavaScriptSerializer();
            DeliveryStatusNotification message         = (DeliveryStatusNotification)serializeObject.Deserialize(responseData, typeof(DeliveryStatusNotification));

            if (null != message)
            {
                this.SaveMessage(message);
            }
        }
    }
Пример #2
0
    /// <summary>
    /// This method reads the incoming message and stores the received message details.
    /// </summary>
    /// <param name="message">InboundSMSMessage, message received from Request</param>
    private void SaveMessage(DeliveryStatusNotification message)
    {
        try
        {
            List <string> list = new List <string>();
            if (File.Exists(Request.MapPath(this.receivedDeliveryStatusFilePath)))
            {
                FileStream   file = new FileStream(Request.MapPath(this.receivedDeliveryStatusFilePath), FileMode.Open, FileAccess.Read);
                StreamReader sr   = new StreamReader(file);
                string       line;

                while ((line = sr.ReadLine()) != null)
                {
                    list.Add(line);
                }

                sr.Close();
                file.Close();
            }

            if (list.Count > this.numberOfDeliveryStatusToStore)
            {
                int diff = list.Count - this.numberOfDeliveryStatusToStore;
                list.RemoveRange(0, diff);
            }

            if (list.Count == this.numberOfDeliveryStatusToStore)
            {
                list.RemoveAt(0);
            }

            string messageLineToStore = message.deliveryInfoNotification.messageId.ToString() + "_-_-" +
                                        message.deliveryInfoNotification.deliveryInfo.address.ToString() + "_-_-" +
                                        message.deliveryInfoNotification.deliveryInfo.deliveryStatus.ToString();
            list.Add(messageLineToStore);
            using (StreamWriter sw = File.CreateText(Request.MapPath(this.receivedDeliveryStatusFilePath)))
            {
                int tempCount = 0;
                while (tempCount < list.Count)
                {
                    string lineToWrite = list[tempCount];
                    sw.WriteLine(lineToWrite);
                    tempCount++;
                }
                sw.Close();
            }
        }
        catch (Exception ex)
        {
            return;
        }
    }
    /// <summary>
    /// This method reads the incoming message and stores the received message details.
    /// </summary>
    /// <param name="message">InboundSMSMessage, message received from Request</param>
    private void SaveMessage(DeliveryStatusNotification message)
    {
        try
        {
            List<string> list = new List<string>();
            FileStream file = new FileStream(Request.MapPath(this.receivedDeliveryStatusFilePath), FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(file);
            string line;

            while ((line = sr.ReadLine()) != null)
            {
                list.Add(line);
            }

            sr.Close();
            file.Close();

            if (list.Count > this.numberOfDeliveryStatusToStore)
            {
                int diff = list.Count - this.numberOfDeliveryStatusToStore;
                list.RemoveRange(0, diff);
            }

            if (list.Count == this.numberOfDeliveryStatusToStore)
            {
                list.RemoveAt(0);
            }

            string messageLineToStore = message.deliveryInfoNotification.messageId.ToString() + "_-_-" +
                            message.deliveryInfoNotification.deliveryInfo.address.ToString() + "_-_-" +
                            message.deliveryInfoNotification.deliveryInfo.deliveryStatus.ToString();
            list.Add(messageLineToStore);
            using (StreamWriter sw = File.CreateText(Request.MapPath(this.receivedDeliveryStatusFilePath)))
            {
                int tempCount = 0;
                while (tempCount < list.Count)
                {
                    string lineToWrite = list[tempCount];
                    sw.WriteLine(lineToWrite);
                    tempCount++;
                }
                sw.Close();
            }
        }
        catch (Exception ex)
        {
            return;
        }
    }
Пример #4
0
 private void Send_DSN_Relayed(Relay_Session session)
 {
     if (session == null)
     {
         return;
     }
     try
     {
         if (!string.IsNullOrEmpty(session.From))
         {
             RelayMessageInfo relayMessageInfo = (RelayMessageInfo)session.QueueTag;
             if ((relayMessageInfo.DSN_Notify & SMTP_DSN_Notify.Success) != SMTP_DSN_Notify.NotSpecified)
             {
                 session.MessageStream.Position = 0L;
                 Mail_Message          mail_Message          = Mail_Message.ParseFromStream(session.MessageStream);
                 RelayVariablesManager relayVariablesManager = new RelayVariablesManager(this, session, "", mail_Message);
                 ServerReturnMessage   serverReturnMessage   = null;
                 if (serverReturnMessage == null)
                 {
                     string bodyTextRft = "{\\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\nYour 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";
                     serverReturnMessage = new ServerReturnMessage("DSN SUCCESSFULLY RELAYED: <#message.header[\"Subject:\"]>", bodyTextRft);
                 }
                 string       rtfText       = relayVariablesManager.Process(serverReturnMessage.BodyTextRtf);
                 Mail_Message mail_Message2 = DeliveryStatusNotification.CreateDsnMessage(session.From, relayVariablesManager.Process(serverReturnMessage.Subject), rtfText, relayMessageInfo.EnvelopeID, relayMessageInfo.Date, null, (session.IsConnected && string.IsNullOrEmpty(session.LocalHostName)) ? session.LocalEndPoint.Address.ToString() : session.LocalHostName, relayMessageInfo.OriginalRecipient, session.To, "relayed", "200 OK", session.RemoteHostName, DateTime.MinValue, DateTime.MinValue, (relayMessageInfo.DSN_Ret == SMTP_DSN_Ret.NotSpecified) ? SMTP_DSN_Ret.Headers : relayMessageInfo.DSN_Ret, mail_Message);
                 using (MemoryStream memoryStream = new MemoryStream())
                 {
                     mail_Message2.ToStream(memoryStream, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                     this.m_pVirtualServer.ProcessAndStoreMessage("", new string[]
                     {
                         session.From
                     }, memoryStream, null);
                 }
                 mail_Message.Dispose();
                 mail_Message2.Dispose();
             }
         }
     }
     catch (Exception x)
     {
         DataSmart.MailServer.Error.DumpError(this.m_pVirtualServer.Name, x);
     }
 }
Пример #5
0
 private void Send_DSN_Delayed(Relay_Session session, string error)
 {
     try
     {
         if (!string.IsNullOrEmpty(session.From))
         {
             RelayMessageInfo relayMessageInfo = (RelayMessageInfo)session.QueueTag;
             if (relayMessageInfo.DSN_Notify == SMTP_DSN_Notify.NotSpecified || (relayMessageInfo.DSN_Notify & SMTP_DSN_Notify.Delay) != SMTP_DSN_Notify.NotSpecified)
             {
                 session.MessageStream.Position = 0L;
                 Mail_Message          mail_Message          = Mail_Message.ParseFromStream(session.MessageStream);
                 RelayVariablesManager relayVariablesManager = new RelayVariablesManager(this, session, error, mail_Message);
                 ServerReturnMessage   serverReturnMessage   = this.DelayedDeliveryMessage;
                 if (serverReturnMessage == null)
                 {
                     string bodyTextRft = "{\\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\nRecipient \\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\nPlease 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\nYour 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";
                     serverReturnMessage = new ServerReturnMessage("Delayed delivery notice: <#message.header[\"Subject:\"]>", bodyTextRft);
                 }
                 string       rtfText       = relayVariablesManager.Process(serverReturnMessage.BodyTextRtf);
                 Mail_Message mail_Message2 = DeliveryStatusNotification.CreateDsnMessage(session.From, relayVariablesManager.Process(serverReturnMessage.Subject), rtfText, relayMessageInfo.EnvelopeID, relayMessageInfo.Date, null, (session.IsConnected && string.IsNullOrEmpty(session.LocalHostName)) ? session.LocalEndPoint.Address.ToString() : session.LocalHostName, relayMessageInfo.OriginalRecipient, session.To, "delayed", error, session.RemoteHostName, DateTime.Now, relayMessageInfo.Date.AddMinutes((double)this.UndeliveredAfter), (relayMessageInfo.DSN_Ret == SMTP_DSN_Ret.NotSpecified) ? SMTP_DSN_Ret.FullMessage : relayMessageInfo.DSN_Ret, mail_Message);
                 using (MemoryStream memoryStream = new MemoryStream())
                 {
                     mail_Message2.ToStream(memoryStream, new MIME_Encoding_EncodedWord(MIME_EncodedWordEncoding.Q, Encoding.UTF8), Encoding.UTF8);
                     this.m_pVirtualServer.ProcessAndStoreMessage("", new string[]
                     {
                         session.From
                     }, memoryStream, null);
                 }
                 mail_Message.Dispose();
                 mail_Message2.Dispose();
             }
         }
     }
     catch (Exception x)
     {
         DataSmart.MailServer.Error.DumpError(this.m_pVirtualServer.Name, x);
     }
 }
Пример #6
0
		static string GetNotifyString (DeliveryStatusNotification notify)
		{
			string value = string.Empty;

			if (notify == DeliveryStatusNotification.Never)
				return "NEVER";

			if ((notify & DeliveryStatusNotification.Success) != 0)
				value += "SUCCESS,";

			if ((notify & DeliveryStatusNotification.Failure) != 0)
				value += "FAILURE,";

			if ((notify & DeliveryStatusNotification.Delay) != 0)
				value += "DELAY";

			return value.TrimEnd (',');
		}
Пример #7
0
        /// <summary>
        /// Creates and sends "Message delivery failed" to message sender.
        /// </summary>
        /// <param name="session">Relay_Session.</param>
        /// <param name="error">Permanent error happened.</param>
        private void Send_DSN_Failed(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 "failure".
                if (relayInfo.DSN_Notify != SMTP_DSN_Notify.NotSpecified && (relayInfo.DSN_Notify & SMTP_DSN_Notify.Failure) == 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.UndeliveredMessage;
                if (messageTemplate == null)
                {
                    string bodyRtf = "" +
                                     "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Verdana;}{\\f1\\fswiss\\fprq2\\fcharset186 Verdana;}{\\f2\\fnil\\fcharset0 Verdana;}{\\f3\\fnil\\fcharset186 Verdana;}{\\f4\\fswiss\\fcharset0 Arial;}{\\f5\\fswiss\\fcharset186{\\*\\fname Arial;}Arial Baltic;}}\r\n" +
                                     "{\\colortbl ;\\red0\\green64\\blue128;\\red255\\green0\\blue0;\\red0\\green128\\blue0;}\r\n" +
                                     "\\viewkind4\\uc1\\pard\\f0\\fs20 Your message t\\lang1061\\f1 o \\cf1\\lang1033\\f2 <#relay.to>\\cf0\\f0 , dated \\b\\fs16 <#message.header[\"Date:\"]>\\b0\\fs20 , could not be delivered.\\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" +
                                     "\\b * Server will not attempt to deliver this message anymore\\b0 .\\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\\f5\\par\r\n" +
                                     "\\lang1033\\f2\\par\r\n" +
                                     "}\r\n";

                    messageTemplate = new ServerReturnMessage("Undelivered 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,
                    "failed",
                    error,
                    session.RemoteHostName,
                    DateTime.Now,
                    DateTime.MinValue,
                    (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);
            }
        }