SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru Raskolnikov's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    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 chotmail.com Type=A: Host not found"

    Thanks for the help.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    South Florida
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    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

    http://www.digitalcoding.com/Code-Sn...ic-values.html

    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
    http://www.digitalcoding.com/free-so...a-Webpage.html


Bookmarks

Posting Permissions

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