Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: help on SMTP
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help on SMTP




On 20 Mar 2007, at 14:23, Marco Piovanelli wrote:

On Tue, 20 Mar 2007 07:00:40 +0000,
Chris Newman (email@hidden) wrote:


Elango C wrote on 3/20/07 9:37 +0530:
I would like to write a code to send the mails from my application. Can any
one help me on this...

The standard protocol for message submission is here: <http://www.apps.ietf.org/rfc/rfc4409.html>

which is based on the SMTP standard:
 <http://www.apps.ietf.org/rfc/rfc2821.html>

You can use CFNetwork to make the network connection if you want the
ability to do more secure (SSL/TLS) submission:

<http://developer.apple.com/documentation/Networking/Conceptual/
CFNetwork/Introduction/chapter_1_section_1.html>

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.

Cheers,

Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
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

References: 
 >help on SMTP (From: "Elango C" <email@hidden>)
 >Re: help on SMTP (From: Chris Newman <email@hidden>)
 >Re: help on SMTP (From: "Marco Piovanelli" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.