-1

Hello i'm making a program in objective-c for iOS, i would like to only check if the smtp server ( after the @ ) exists by ping it or doing a HTTP request on it and get in return the status ( 200 ).

what i'm doing now it's getting the UITextField.text, cutting it, getting the substring after the @ and doing this... but it is not working...

        NSError *error = nil;
        NSURL *url = [NSURL URLWithString:@"gmail.com"];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];;
        NSURLResponse *response = nil;
        NSData *data=[[NSData alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]];
        NSString* retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        // you can use retVal , ignore if you don't need.
        NSInteger httpStatus = [((NSHTTPURLResponse *)response) statusCode];
        NSLog(@"responsecode: %d", httpStatus);
        // there will be various HTTP response code (status)
        // you might concern with 404
        if(httpStatus == 200)
        {
            NSLog(@"FEELIX CONTENT");
            // do your job
        }
        else
        {
            NSLog(@"FOCK!");
        }
xGoPox
  • 674
  • 8
  • 23

2 Answers2

0

If you have a domain, the mail server for that domain is specified by the MX DNS record. For example:

$ host -t MX gmail.com
gmail.com mail is handled by 5 gmail-smtp-in.l.google.com.
gmail.com mail is handled by 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 10 alt1.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail is handled by 20 alt2.gmail-smtp-in.l.google.com.

The number is a priority indication. To check a server, check that you can connect to port 25 of that server.

Sjoerd
  • 74,049
  • 16
  • 131
  • 175
0

I'm not sure what you're trying to do here. But maybe you missed something:

The part behind the @ sign is not necesarily the SMTP server. The SMTP server is determined by querying DNS for the MX record (Mail Exchange) which returns the SMTP server.

On windows you could do on the commandline:

nslookup -type=mx gmail.com

to get the SMTP-Servers.

See http://en.wikipedia.org/wiki/MX_record for more details.

bidifx
  • 1,640
  • 13
  • 19