cvs: peardoc /en/package/networking/net-smtp intro.xml

From: Date: Sat, 10 May 2008 20:42:36 +0000
Subject: cvs: peardoc /en/package/networking/net-smtp intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-10775@lists.php.net to get a copy of this message
cweiske Sat May 10 20:42:36 2008 UTC Modified files: /peardoc/en/package/networking/net-smtp intro.xml Log: Move SMTP intro from the external wiki page into peardoc

http://cvs.php.net/viewvc.cgi/peardoc/en/package/networking/net-smtp/intro.xml?r1=1.3&r2=1.4&diff_format=u Index: peardoc/en/package/networking/net-smtp/intro.xml diff -u peardoc/en/package/networking/net-smtp/intro.xml:1.3 peardoc/en/package/networking/net-smtp/intro.xml:1.4 --- peardoc/en/package/networking/net-smtp/intro.xml:1.3 Wed Dec 12 05:17:04 2007 +++ peardoc/en/package/networking/net-smtp/intro.xml Sat May 10 20:42:36 2008 @@ -1,23 +1,280 @@ -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <refentry id="package.networking.net-smtp.intro"> - <refnamediv> - <refname>Introduction and Guide</refname> - <refpurpose> -Provides an implementation of the SMTP protocol </refpurpose> - </refnamediv> - <refsect1> - <title>Net_SMTP Introduction and Guide</title> + <refnamediv> + <refname>Introduction and Guide</refname> + <refpurpose> + Provides an implementation of the SMTP protocol + </refpurpose> + </refnamediv> + + <refsect1> + <title>Net_SMTP Introduction and Guide</title> + <para> + The <classname>Net_SMTP</classname> package supports the SMTP + authentication standard (as defined by RFC-2554). + <classname>Net_SMTP</classname> supports several authentication + methods like DIGEST-MD5, CRAM-MD5, LOGIN and PLAIN. + </para> + </refsect1> + + <refsect1> + <title>Dependencies</title> + + <refsect2> + <title>The PEAR_Error Class</title> + <para> + The Net_SMTP package uses the + <link linkend="core.pear.pear-error"><classname>PEAR_Error</classname></link> + class for all of its error handling. + </para> + </refsect2> + + <refsect2> + <title>The Net_Socket Package</title> + <para> + The + <ulink url="&url.pear.package;Net_Socket"><classname>Net_Socket</classname></ulink> + package is used as the basis for all network communications. + </para> + </refsect2> + + <refsect2> + <title>The Auth_SASL Package</title> + <para> + The + <ulink url="&url.pear.package;Auth_SASL"><classname>Auth_SASL</classname></ulink> + package is an optional dependency. + If it is available, the <classname>Net_SMTP</classname> package will be + able to support the DIGEST-MD5 and CRAM-MD5 SMTP authentication methods. + Otherwise, only the LOGIN and PLAIN methods will be available. + </para> + </refsect2> + + </refsect1> + + + <refsect1> + <title>Error Handling</title> + + <para> + All of the <classname>Net_SMTP</classname> class's public methods return a + <link linkend="core.pear.pear-error"><classname>PEAR_Error</classname></link> + object if an error occurs. + The standard way to check for a <classname>PEAR_Error</classname> object is + by using + <link linkend="core.pear.pear.iserror">PEAR::isError()</link> + </para> + </refsect1> + + + <refsect1> + <title>SMTP Authentication</title> + <para> + The Net_SMTP package supports the SMTP authentication standard + (as defined by <ulink url="&url.rfc;2554">RFC-2554</ulink>). + The Net_SMTP package supports the following authentication methods, + in order of preference: + </para> + + + <refsect2> + <title>DIGEST-MD5</title> + <para> + The DIGEST-MD5 authentication method uses RSA Data Security Inc.'s + MD5 Message Digest algorithm. + It is considered the most secure method of SMTP authentication. + </para> + + <note> <para> -The Net_SMTP package supports the SMTP authentication standard (as defined by RFC-2554). -Net_SMTP supports several authentication methods like DIGEST-MD5,CRAM-MD5, LOGIN and PLAIN. + The DIGEST-MD5 authentication method is only supported if the + AUTH_SASL package is available. + </para> + </note> + </refsect2> + + + <refsect2> + <title>CRAM-MD5</title> + <para> + The CRAM-MD5 authentication method has been superseded by the + DIGEST-MD5 method in terms of security. + It is provided here for compatibility with older SMTP servers that + may not support the newer DIGEST-MD5 algorithm. + </para> + + <note> + <para> + The CRAM-MD5 authentication method is only supported if the + AUTH_SASL package is available. + </para> + </note> + </refsect2> + + + <refsect2> + <title>LOGIN</title> + <para> + The LOGIN authentication method encrypts the user's password using + the Base64 encoding scheme. + Because decrypting a Base64-encoded string is trivial, + LOGIN is not considered a secure authentication method + and should be avoided. + </para> + </refsect2> + + + <refsect2> + <title>PLAIN</title> + <para> + The PLAIN authentication method sends the user's password in plain text. + This method of authentication is not secure and should be avoided. + </para> + </refsect2> + + </refsect1> + + + <refsect1> + <title>Secure Connections</title> + + <para> + If <ulink url="&url.php.manual.auto;transports">secure socket transports</ulink> + have been enabled in PHP, it is possible to establish + a secure connection to the remote SMTP server: + </para> + + <programlisting role="php"><![CDATA[ +$smtp = new Net_SMTP('ssl://mail.example.com', 465); +]]></programlisting> + + <para> + This example connects to mail.example.com on port 465 + (a common SMTPS port) using the ssl:// transport. + </para> + </refsect1> + + + <refsect1> + <title>Data Quoting</title> + + <para> + By default, all outbound string data is quoted in accordance with + SMTP standards. This means that all native Unix (\n) and Mac (\r) + line endings are converted to Internet-standard CRLF (\r\n) line endings. + Also, because the SMTP protocol uses a single leading period (.) + to signal an end to the message data, single leading periods + in the original data string are "doubled" (e.g. ".."). + </para> + <para> + These string transformation can be expensive when large blocks of data + are involved. + For example, the Net_SMTP package is not aware of MIME parts + (it just sees the MIME message as one big string of characters), + so it is not able to skip non-text attachments when searching for + characters that may need to be quoted. + </para> + <para> + Because of this, it is possible to extend the Net_SMTP class + in order to implement your own custom quoting routine. + Just create a new class based on the Net_SMTP class + and reimplement the quotedata() method: + </para> + + <programlisting role="php"><![CDATA[ +require 'Net/SMTP.php'; + +class Net_SMTP_custom extends Net_SMTP +{ + function quotedata($data) + { + /* Perform custom data quoting */ + } +} +]]></programlisting> + + <para> + Note that the $data parameter will be passed to the quotedata() + function by reference. + This means that you can operate directly on $data. + It also the overhead of copying a large $data string to and + from the quotedata() method. + </para> + </refsect1> + + + <refsect1> + <title>Debugging</title> + + <para> + The Net_SMTP package contains built-in debugging output routines + (disabled by default). + Debugging output must be explicitly enabled via the setDebug() method: + </para> + + <programlisting role="php"><![CDATA[ +$smtp->setDebug(true); +]]></programlisting> + + <para> + The debugging messages will be sent to the standard output stream. + </para> + </refsect1> + + + <refsect1> + <title>Examples</title> + + <para> + The following script demonstrates how a simple email message can be + sent using the Net_SMTP package: + </para> + + <programlisting role="php"><![CDATA[ +<?php +require 'Net/SMTP.php'; + +$host = 'mail.example.com'; +$from = 'user@example.com'; +$rcpt = array('recipient1@example.com', 'recipient2@example.com'); +$subj = "Subject: Test Message\n"; +$body = "Body Line 1\nBody Line 2"; + +/* Create a new Net_SMTP object. */ +if (! ($smtp = new Net_SMTP($host))) { + die("Unable to instantiate Net_SMTP object\n"); +} + +/* Connect to the SMTP server. */ +if (PEAR::isError($e = $smtp->connect())) { + die($e->getMessage() . "\n"); +} + +/* Send the 'MAIL FROM:' SMTP command. */ +if (PEAR::isError($smtp->mailFrom($from))) { + die("Unable to set sender to <$from>\n"); +} + +/* Address the message to each of the recipients. */ +foreach ($rcpt as $to) { + if (PEAR::isError($res = $smtp->rcptTo($to))) { + die("Unable to add recipient <$to>: " . $res->getMessage() . "\n"); + } +} + +/* Set the body of the message. */ +if (PEAR::isError($smtp->data($subj . "\r\n" . $body))) { + die("Unable to send data\n"); +} + +/* Disconnect from the SMTP server. */ +$smtp->disconnect(); +?> +]]></programlisting> + + </refsect1> + </refentry> -</para> - <para> -<ulink url="&url.net_smtp.home;">The full guide is available here</ulink> - </para> - </refsect1> - </refentry> - <!-- Keep this comment at the end of the file Local variables: mode: sgml
« previous php.pear.doc (#10775) next »