| version 1.1, 2002/09/29 22:34:34 |
version 1.2, 2002/10/21 13:04:56 |
| Line 2 Libsmtp - A simple SMTP library (C)opyri |
|
| Line 2 Libsmtp - A simple SMTP library (C)opyri |
|
| |
|
| API |
API |
| |
|
| The API for Libsmtp is very simple, with only four functions available. They allow |
The API for Libsmtp is very simple, with only four functions available. They |
| you to connect to a server, send a mail, and disconnect from the server. |
allow you to connect to a server, send a mail, and disconnect from the server. |
| |
|
| The functions as defined in inc/libsmtp.h are as follows: |
The functions as defined in inc/libsmtp.h are as follows: |
| |
|
| Line 16 A simple example is provided at the end |
|
| Line 16 A simple example is provided at the end |
|
| |
|
| smtp_connect() |
smtp_connect() |
| |
|
| The smtp_connect() function attempts to connect to the given SMTP server on the port |
The smtp_connect() function attempts to connect to the given SMTP server on the |
| requested. For example, to attempt a connection to the server "mail.isp.com" on the |
port requested. For example, to attempt a connection to the server |
| default SMTP port (25), you would use: |
"mail.isp.com" on the default SMTP port (25), you would use: |
| |
|
| smtp_connect("mail.isp.com",25); |
smtp_connect("mail.isp.com",25); |
| |
|
| smtp_connect() will return 0 on success or one of the following error messages if a |
smtp_connect() will return 0 on success or one of the following error messages |
| connection to the server could not be made. |
if a connection to the server could not be made. |
| |
|
| -SMTP_UNKNOWN_SERVER - The server could not be found (I.E the DNS lookup |
-SMTP_UNKNOWN_SERVER - The server could not be found (I.E the DNS lookup |
| failed) |
failed) |
| -SMTP_CONNECT_FAILED - Libsmtp could not connect to the server. It could |
-SMTP_CONNECT_FAILED - Libsmtp could not connect to the server. |
| be that the port you have requested is incorrect. |
It could be that the port you have requested is incorrect. |
| -SMTP_TIMED_OUT - The remote server did not respond before the set |
-SMTP_TIMED_OUT - The remote server did not respond before the set |
| time allowed (See smtp_set_timeout() for more |
time allowed (See smtp_set_timeout() for more |
| information) |
information) |
| |
|
| smtp_sendmail() |
smtp_sendmail() |
| |
|
| The smtp_sendmail() function will attempt to send an (Already formated) mail to the |
The smtp_sendmail() function will attempt to send an (Already formated) mail to |
| user or users requested. As an example, if you wanted to send a mail to the users |
the user or users requested. As an example, if you wanted to send a mail to |
| "fred@foo.com" and "jane@baz.org", and you are "frodo@bagend.com" you could use: |
the users "fred@foo.com" and "jane@baz.org", and you are "frodo@bagend.com" you |
| |
could use: |
| |
|
| smtp_sendmail("fred@foo.com, jane@baz.org","frodo@bagend.com",&message); |
smtp_sendmail("fred@foo.com, jane@baz.org","frodo@bagend.com",&message); |
| |
|
| smtp_sendmail() will return 0 on success or one of the following error messages if |
smtp_sendmail() will return 0 on success or one of the following error messages |
| the mail could not be sent. |
if the mail could not be sent. |
| |
|
| -SMTP_INVALID_FROM - The "From" address you are attempting to use is |
-SMTP_INVALID_FROM - The "From" address you are attempting to use is |
| invalid in some way. |
invalid in some way. |
| Line 54 the mail could not be sent. |
|
| Line 55 the mail could not be sent. |
|
| time allowed (See smtp_set_timeout() for more |
time allowed (See smtp_set_timeout() for more |
| information) |
information) |
| |
|
| Note: smtp_sendmail() assumes that you have already formated your mail according to |
Note: smtp_sendmail() assumes that you have already formated your mail |
| the relevant RFC's, I.E you have created the basic headers, your message does not |
according to the relevant RFC's, I.E you have created the basic headers, your |
| contain any invalid characters, and you have done any encoding (E.g Quoted |
message does not contain any invalid characters, and you have done any encoding |
| Printable, Base64 etc) on the message yourself. In practice for smaller messages |
(E.g Quoted Printable, Base64 etc) on the message yourself. In practice for |
| this is not difficult. smtp_sendmail() will not perform any formatting or validity |
smaller messages this is not difficult. smtp_sendmail() will not perform any |
| checking on the message you are trying to send. |
formatting or validity checking on the message you are trying to send. |
| |
|
| smtp_disconnect() |
smtp_disconnect() |
| |
|
| The smtp_disconnect() function will attempt to disconnect cleanly from the remote |
The smtp_disconnect() function will attempt to disconnect cleanly from the |
| server, and closes connection to the server. There are no arguments to |
remote server, and closes connection to the server. There are no arguments to |
| smtp_disconnect(), and the function will either return 0 on success, or |
smtp_disconnect(), and the function will either return 0 on success, or |
| -SMTP_DISCONNECT_FAILED if libsmtp could not disconnect properly from the server. In |
-SMTP_DISCONNECT_FAILED if libsmtp could not disconnect properly from the |
| either instance, the connection to the server will be closed. |
server. In either instance, the connection to the server will be closed. |
| |
|
| smtp_set_timeout() |
smtp_set_timeout() |
| |
|
| By default, libsmtp will timeout and return an error if it does receive a response |
By default, libsmtp will timeout and return an error if it does receive a |
| from the server after 30 seconds. You can change this timeout value with the |
response from the server after 30 seconds. You can change this timeout value |
| smtp_set_timeout() function. There are no upper or lower limits on the timeout |
with the smtp_set_timeout() function. There are no upper or lower limits on |
| value you can set, but a timeout value of 0 is "No timeout", which means that |
the timeout value you can set, but a timeout value of 0 is "No timeout", which |
| libsmtp will sit and wait indefinatly for the server to respond. Conversely, a very |
means that libsmtp will sit and wait indefinatly for the server to respond. |
| large timeout value will cause libsmtp to seem to be waiting forever for the server |
Conversely, a very large timeout value will cause libsmtp to seem to be waiting |
| to respond! You should be careful about the values you use. Something between 20 |
forever for the server to respond! You should be careful about the values you |
| and 120 seconds is probably a good value to use. |
use. Something between 20 and 120 seconds is probably a good value to use. |
| |
|
| Example Usage |
Example Usage |
| |
|
| Below is a very simple example for using libsmtp. The code attempts to connect to |
Below is a very simple example for using libsmtp. The code attempts to connect |
| the (Fictional) server "mail.isp.com" on the default SMTP port, and sends a simple |
to the (Fictional) server "mail.isp.com" on the default SMTP port, and sends a |
| "Hello World!" message to two (Fictional) users, "fred@foo.com" and "jane@baz.org" |
simple "Hello World!" message to two (Fictional) users, "fred@foo.com" and |
| |
"jane@baz.org" |
| |
|
| --Begin Example-- |
--Begin Example-- |
| |
|
| Line 134 include all the headers required by RFC2 |
|
| Line 136 include all the headers required by RFC2 |
|
| |
|
| --End Example-- |
--End Example-- |
| |
|
| |
|