0

Can anyone know how to check smtp connection in objective c,without using any third party libraries like skpsmtp or mailcore. Please help.

  • double check: you want to do it in iOS App? or OSX App? – Raptor Dec 28 '12 at 07:19
  • why do you require smtp? You could just manage with MFMailComposer. – zahreelay Dec 28 '12 at 07:26
  • Its for iOS app and i need the smtp for sending the mails.I tried some third party libraries but its difficult to check the smtp connection and also difficult to send attachments – Sooraj Sr Dec 28 '12 at 07:31
  • check this out dude http://stackoverflow.com/questions/7087199/xcode-4-ios-send-an-email-using-smtp-from-inside-my-app – spider1983 Dec 28 '12 at 07:43
  • I understand that,its the native mfmailcomposer,but i need to send smtp mails,for that first i need to check the server is aviailable or not.if we can check the smtp connection in any third party library,that is also okay – Sooraj Sr Dec 28 '12 at 07:56

1 Answers1

0

I would suggest to open a TCP socket to your remote SMTP server, port 25. If the connection opens and returns 220 code, it means that the server is available and reachable.

This would be similar to the telnet command

sst:~ sst$ telnet relay.skynet.be 25
Trying 195.238.5.128...
Connected to relay.skynet.be (195.238.5.128).
Escape character is '^]'.
220 relay.skynet.be ESMTP
quit
221 relay.skynet.be
Connection closed by foreign host.

Doing so with Cocoa requires some coding although. This is documented in Cocoa Stream Developer Guide at http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/Streams/Streams.html#//apple_ref/doc/uid/10000188-SW1

Or you always have the choice to fall back to good old C code, like explained here : How to Create a TCP socket connect using C to a predefined port

Community
  • 1
  • 1
Sébastien Stormacq
  • 14,301
  • 5
  • 41
  • 64
  • Thanks for your valuable reply..As i am new to ios could please explain how to add this c code to our objective c.I need to check the smtp server connection only. – Sooraj Sr Dec 28 '12 at 11:31
  • there is nothing special to do : just include the proper header (.h) files and write your C code inside your Objective-C classes. – Sébastien Stormacq Dec 29 '12 at 13:10