Hunny Software Library Reference

SmtpClient Class

Class that represents an SMTP client connection.

For a list of all members of this type, see SmtpClient Members.

System.Object
   SmtpClient

[Visual Basic]
Public Class SmtpClient
Implements IDisposable
[C#]
public class SmtpClient : IDisposable

Remarks

SmtpClient is a class that manages the client side of an SMTP connection. Specifically, SmtpClient provides facilities for opening a connection to an SMTP server, sending commands to the server, receiving responses from the server, and closing the connection. SmtpClient implements the SMTP protocol as defined in RFC 2821, with extensions defined by various other RFCs.

To use SmtpClient, you first call the Connect method to open a connection to the SMTP server. Once you have opened the connection, you send SMTP commands to the server using various methods. In the typical case, you start with the EHLO command, then complete one or more mail transactions via the MAIL, RCPT, and DATA commands, and finally finish with the QUIT command. You send these commands using the Ehlo, MailFrom, RcptTo, Data, and Quit methods. After you have finished sending commands, you call the Disconnect method to close the connection to the server.

When you send an SMTP client command, you must be prepared to handle errors. If a network error occurs, the library throws an instance of Hunny.Mail.Exception. Your program should be prepared to catch this exception. In addition to network errors, your code should be prepared to handle SMTP server errors. After you invoke a client command, you should check the ReplyCode property to see if the command succeeded or failed at the SMTP server. Reply codes are specified in RFC 2821. The documentation for the command methods provides additional information about the meaning of reply codes for specific commands. You may also want to get the ReplyText property, which contains the text of the server's reply.

One advanced feature of SmtpClient is the ability to cancel a network operation. For example, if you are developing an interactive application with a user interface, you can allow the user to cancel a network operation that has stalled. To provide this ability, SmtpClient provides a Cancel method that you can call from your user interface thread, which is a different thread from the thread that is controlling the SMTP connection.

Requirements

Namespace: Hunny.Mail

Assembly: Hunny.Mail (in Hunny.Mail.dll)

See Also

SmtpClient Members | Hunny.Mail Namespace | RFC 2821: Simple Mail Transfer Protocol