示例#1
0
        /// <summary>
        /// Creates a MantaEvent object and Fills it with the values from the data record.
        /// </summary>
        /// <param name="record">Record to get the data from.</param>
        /// <returns>MantaAubseEvent or MantaBounceEvent</returns>
        private static MantaEvent CreateAndFillMantaEventFromRecord(IDataRecord record)
        {
            MantaEventType type      = (MantaEventType)record.GetInt32("evn_type_id");
            MantaEvent     thisEvent = null;

            switch (type)
            {
            case MantaEventType.Abuse:
                thisEvent = new MantaAbuseEvent();
                break;

            case MantaEventType.Bounce:
                thisEvent = new MantaBounceEvent();
                FillMantaBounceEvent((thisEvent as MantaBounceEvent), record);
                break;

            case MantaEventType.TimedOutInQueue:
                thisEvent = new MantaTimedOutInQueueEvent();
                break;

            default:
                throw new NotImplementedException("Unknown Event Type (" + type + ")");
            }

            thisEvent.EmailAddress = record.GetString("evn_event_emailAddress");
            thisEvent.EventTime    = record.GetDateTime("evn_event_timestamp");
            thisEvent.EventType    = type;
            thisEvent.ID           = record.GetInt32("evn_event_id");
            thisEvent.SendID       = record.GetString("snd_send_id");
            thisEvent.Forwarded    = record.GetBoolean("evn_event_forwarded");
            return(thisEvent);
        }
示例#2
0
        /// <summary>
        /// Examines an SMTP response message to identify detailed bounce information from it.
        /// </summary>
        /// <param name="response">The message that's come back from an external MTA when attempting to send an email.</param>
        /// <param name="rcptTo">The email address that was being sent to.</param>
        /// <param name="internalSendID">The internal Manta SendID.</param>
        /// <returns>True if a bounce was found and recorded, false if not.</returns>
        internal bool ProcessSmtpResponseMessage(string response, string rcptTo, int internalSendID, out EmailProcessingDetails bounceIdentification)
        {
            bounceIdentification = new EmailProcessingDetails();



            // Check for TimedOutInQueue message first.
            if (response.Equals(MtaParameters.TIMED_OUT_IN_QUEUE_MESSAGE, StringComparison.OrdinalIgnoreCase))
            {
                bounceIdentification = null;

                MantaTimedOutInQueueEvent timeOut = new MantaTimedOutInQueueEvent
                {
                    EventType    = MantaEventType.TimedOutInQueue,
                    EmailAddress = rcptTo,
                    SendID       = SendDB.GetSend(internalSendID).ID,
                    EventTime    = DateTime.UtcNow
                };

                // Log to DB.
                Save(timeOut);

                // All done return true.
                return(true);
            }



            BouncePair bouncePair    = new BouncePair();
            string     bounceMessage = string.Empty;


            if (ParseBounceMessage(response, out bouncePair, out bounceMessage, out bounceIdentification))
            {
                // Were able to find the bounce so create the bounce event.
                MantaBounceEvent bounceEvent = new MantaBounceEvent
                {
                    EventType    = MantaEventType.Bounce,
                    EmailAddress = rcptTo,
                    BounceInfo   = bouncePair,
                    SendID       = SendDB.GetSend(internalSendID).ID,
                    // It is possible that the bounce was generated a while back, but we're assuming "now" for the moment.
                    // Might be good to get the DateTime found in the email at a later point.
                    EventTime = DateTime.UtcNow,
                    Message   = response
                };

                // Log to DB.
                Save(bounceEvent);


                // All done return true.
                return(true);
            }



            // Couldn't identify the bounce.

            bounceIdentification.BounceIdentifier = BounceIdentifier.NotIdentifiedAsABounce;

            return(false);
        }