CFNetwork gives you a nice abstraction layer over BSD sockets,
and is easier to work with, especially in the context of a run
loop-based application, but in order to submit a message to an
SMTP server with CFNetwork, you still need to write a substantial
amount of code.
It depends what you want to do. SMTP is a very simple protocol and
if you have a server that is configured to accept the mail, it's
quite easy. Here's a snippet from an internal app (it uses our
networking and has no error checking but it should be fairly self-
explanatory):
XString response;
// Contact the server
XNetAddress serverAddress( "mail.improvision.com", 25 );
XNetEndpoint ep;
ep.Connect( serverAddress, 30000 );
XNetStream stream( ep );
// Get our address
XNetAddress ourAddress;
ourAddress.SetToLocalAddress();
// Read the hello message
response = stream.ReadLine();
// Initiate the message
stream.WriteText( "HELO " + ourAddress.GetDescription() + "\r\n" );
response = stream.ReadLine();
stream.WriteText( "MAIL FROM: <email@hidden>\r\n" );
response = stream.ReadLine();
stream.WriteText( "RCPT TO: <email@hidden>\r\n" );
response = stream.ReadLine();
stream.WriteText( "DATA\r\n" );
response = stream.ReadLine();
// Write some general info
stream.WriteText( "From: email@hidden\r\n" );
stream.WriteText( "To: email@hidden\r\n" );
stream.WriteText( "Subject: This is an e-mail\r\n" );
stream.WriteText( "\r\n" );
stream.WriteText( "Some body text\r\n" );
stream.WriteText( "\r\n" );
// Finish the message
stream.WriteText( "\r\n.\r\n" );
response = stream.ReadLine();
stream.WriteText( "QUIT\r\n" );
response = stream.ReadLine();
As other posters have said however, the hard bit comes if you need
authentication etc. to handle anti-spam measures on the server.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden