Beispiel #1
0
        /// <summary>
        /// Stores message for relay.
        /// </summary>
        /// <param name="queueName">Queue name where to store message.</param>
        /// <param name="id">Message ID. Guid value is suggested.</param>
        /// <param name="envelopeID">Envelope ID_(MAIL FROM: ENVID).</param>
        /// <param name="date">Message date.</param>
        /// <param name="message">Message to store. Message will be readed from current position of stream.</param>
        /// <param name="targetHost">Target host or IP where to send message. This value can be null, then DNS MX o A record is used to deliver message.</param>
        /// <param name="sender">Sender address to report to target server.</param>
        /// <param name="to">Message recipient address.</param>
        /// <param name="originalRecipient">Original recipient(RCPT TO: ORCPT).</param>
        /// <param name="notify">DSN notify condition.</param>
        /// <param name="ret">Specifies what parts of message are returned in DSN report.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>queueName</b>,<b>id</b>,<b>message</b> or <b>to</b> is null.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the argumnets has invalid value.</exception>
        private void StoreRelayMessage(string queueName, string id, string envelopeID, DateTime date, Stream message, HostEndPoint targetHost, string sender, string to, string originalRecipient, SMTP_DSN_Notify notify, SMTP_DSN_Ret ret)
        {
            if (queueName == null)
            {
                throw new ArgumentNullException("queueName");
            }
            if (queueName == "")
            {
                throw new ArgumentException("Argumnet 'queueName' value must be specified.");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id == "")
            {
                throw new ArgumentException("Argument 'id' value must be specified.");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (to == null)
            {
                throw new ArgumentNullException("to");
            }
            if (to == "")
            {
                throw new ArgumentException("Argument 'to' value must be specified.");
            }

            string path = m_pVirtualServer.MailStorePath + queueName;

            // Check if Directory exists, if not Create
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // Create relay message.
            using (FileStream fs = File.Create(API_Utlis.PathFix(path + "\\" + id + ".eml")))
            {
                SCore.StreamCopy(message, fs);

                // Create message info file for the specified relay message.
                RelayMessageInfo messageInfo = new RelayMessageInfo(
                    envelopeID,
                    sender,
                    to,
                    originalRecipient,
                    notify,
                    ret,
                    date,
                    false,
                    targetHost
                    );
                File.WriteAllBytes(API_Utlis.PathFix(path + "\\" + id + ".info"), messageInfo.ToByte());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Raises <b>SessionCompleted</b> event.
        /// </summary>
        /// <param name="session">Session what completed processing.</param>
        /// <param name="exception">Exception happened or null if relay completed successfully.</param>
        protected override void OnSessionCompleted(Relay_Session session, Exception exception)
        {
            base.OnSessionCompleted(session, exception);

            try{
                FileStream       messageStream = (FileStream)session.MessageStream;
                RelayMessageInfo messageInfo   = (RelayMessageInfo)session.QueueTag;

                bool deleteMessage = false;
                // Message relayed sucessfully, delete message.
                if (exception == null)
                {
                    deleteMessage = true;

                    Send_DSN_Relayed(session);
                }
                // Message relay failed.
                else
                {
                    bool permanentError = false;
                    if (exception is SMTP_ClientException)
                    {
                        permanentError = ((SMTP_ClientException)exception).IsPermanentError;
                    }

                    // If permanent error or undelivered time reached, send undelivered message to sender and delete message.
                    if (permanentError || messageInfo.Date.AddMinutes(m_UndeliveredAfter) < DateTime.Now)
                    {
                        // Send undelivered notify message.
                        Send_DSN_Failed(session, exception.Message);

                        deleteMessage = true;
                    }
                    else
                    {
                        // Move message to "Retry" queue.
                        if (session.Queue.Name.ToLower() == "relay")
                        {
                            session.MessageStream.Position = 0;
                            StoreRelayMessage(
                                "Retry",
                                Path.GetFileNameWithoutExtension(messageStream.Name),
                                messageInfo.EnvelopeID,
                                messageInfo.Date,
                                session.MessageStream,
                                messageInfo.HostEndPoint,
                                messageInfo.Sender,
                                messageInfo.Recipient,
                                messageInfo.OriginalRecipient,
                                messageInfo.DSN_Notify,
                                messageInfo.DSN_Ret
                                );

                            deleteMessage = true;
                        }
                        else
                        {
                            // See delayed delivery warning must be sent.
                            if (!messageInfo.DelayedDeliveryNotifySent && DateTime.Now > messageInfo.Date.AddMinutes(this.DelayedDeliveryNotifyAfter))
                            {
                                Send_DSN_Delayed(session, exception.Message);

                                // Update relay mesage info UndeliveredWarning flag.
                                messageInfo.DelayedDeliveryNotifySent = true;
                                File.WriteAllBytes(messageStream.Name.Replace(".eml", ".info"), messageInfo.ToByte());
                            }
                        }
                    }
                }

                if (deleteMessage)
                {
                    File.Delete(messageStream.Name);
                    File.Delete(messageStream.Name.Replace(".eml", ".info"));
                }
                messageStream.Dispose();
            }
            catch (Exception x) {
                LumiSoft.MailServer.Error.DumpError(m_pVirtualServer.Name, x);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Stores message for relay.
        /// </summary>
        /// <param name="queueName">Queue name where to store message.</param>
        /// <param name="id">Message ID. Guid value is suggested.</param>
        /// <param name="envelopeID">Envelope ID_(MAIL FROM: ENVID).</param>
        /// <param name="date">Message date.</param>
        /// <param name="message">Message to store. Message will be readed from current position of stream.</param>
        /// <param name="targetHost">Target host or IP where to send message. This value can be null, then DNS MX o A record is used to deliver message.</param>
        /// <param name="sender">Sender address to report to target server.</param>
        /// <param name="to">Message recipient address.</param>
        /// <param name="originalRecipient">Original recipient(RCPT TO: ORCPT).</param>
        /// <param name="notify">DSN notify condition.</param>
        /// <param name="ret">Specifies what parts of message are returned in DSN report.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>queueName</b>,<b>id</b>,<b>message</b> or <b>to</b> is null.</exception>
        /// <exception cref="ArgumentException">Is raised when any of the argumnets has invalid value.</exception>
        private void StoreRelayMessage(string queueName,string id,string envelopeID,DateTime date,Stream message,HostEndPoint targetHost,string sender,string to,string originalRecipient,SMTP_DSN_Notify notify,SMTP_DSN_Ret ret)
        {
            if(queueName == null){
                throw new ArgumentNullException("queueName");
            }
            if(queueName == ""){
                throw new ArgumentException("Argumnet 'queueName' value must be specified.");
            }
            if(id == null){
                throw new ArgumentNullException("id");
            }
            if(id == ""){
                throw new ArgumentException("Argument 'id' value must be specified.");
            }
            if(message == null){
                throw new ArgumentNullException("message");
            }
            if(to == null){
                throw new ArgumentNullException("to");
            }
            if(to == ""){
                throw new ArgumentException("Argument 'to' value must be specified.");
            }
					
			string path = m_pVirtualServer.MailStorePath + queueName;

			// Check if Directory exists, if not Create
			if(!Directory.Exists(path)){
				Directory.CreateDirectory(path);
			}

			// Create relay message.
			using(FileStream fs = File.Create(API_Utlis.PathFix(path + "\\" + id + ".eml"))){
                SCore.StreamCopy(message,fs);
                               
                // Create message info file for the specified relay message.
                RelayMessageInfo messageInfo = new RelayMessageInfo(
                    envelopeID,
                    sender,
                    to,
                    originalRecipient,
                    notify,
                    ret,
                    date,
                    false,
                    targetHost
                );
                File.WriteAllBytes(API_Utlis.PathFix(path + "\\" + id + ".info"),messageInfo.ToByte());
			}
        }