SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    0 Post(s)
    0 Thread(s)

    SMTP Server Response Regular Expression

    I am tryinng to put together some sort of regular expression to work with responses and codes.

    Most responses begin with a 3 digit number such as 250, 550, etc.

    on occasion we will receive a response not beginning with any number.

    then most, not all contain an 3 digit error code separated by periods. Example 5.1.1, 5.0.4, etc.

    I have three columns, Status Message (entire response message), Status Code (3 digit code), Error Code(3 digit with periods).

    I am trying to generate a regular expression that might help me pull the status code and the error code out of the response message, and if either of them do not exisist the column would get a value of 0.

    here is an example with both status and error code (note, status code and error code may not always be back to back as in this example):

    "550 5.1.1 Invalid recipient: E3210 In response to the RCPT TO command"

    Here is an exampl of a resonse with no status or error code:

    "Name service error for Type=A: Host not found"

    Thanks for the help.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    South Florida
    0 Post(s)
    0 Thread(s)
    I am not sure which .Net language you are using, Here is a code snippet in C# to extract numeric values using regex

    I would consider only keeping two columns and removing 3 digit with period. You can write a simple function to extract numbers (and merge them in to one number if its separated by period) and run the match.

    Here is a small program which check for response header


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts