Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A .NET Wizard control

, 24 Apr 2003 CPOL
A .NET Wizard control for the VS.IDE and client apps
ak_wizard_src.zip
UtilityLibrary
Collections
Combos
CommandBars
DateTimeControls
Dialogs
Gantt Chart
General
licenses.licx
Menus
mssccprj.scc
Notification
OutlookBar
Resources
Serialization
Smtp
Strong Keys
TreeListView
UtilityLibrary.csproj.user
UtilityLibrary.csproj.vspscc
UtilityLibrary.suo
vssver.scc
WinControls
Wizards
vssver.scc
CheckCombo.bmp
DateCombo.bmp
TreeCombo.bmp
vssver.scc
vssver.scc
CalendarViewEx.bmp
TimeEditor.bmp
vssver.scc
FolderSelectDialog.bmp
vssver.scc
vssver.scc
vssver.scc
ContextMenuEx.bmp
MainMenuEx.bmp
vssver.scc
TaskbarNotifier.bmp
ToolTipEx.bmp
vssver.scc
vssver.scc
DragCursor.cur
vssver.scc
vssver.scc
vssver.scc
UtilityLibStrongKey.snk
vssver.scc
vssver.scc
NotifyIconEx.bmp
PictureBoxEx.bmp
TextBoxEx.bmp
TextComboBox.bmp
vssver.scc
LineFrame.bmp
vssver.scc
WizardForm.bmp
UtilityLibrary.Designers
bin
mssccprj.scc
Strong Keys
UtilityLibrary.Designers.csproj.user
UtilityLibrary.Designers.csproj.vspscc
vssver.scc
Debug
UtilityLibStrongKey.snk
vssver.scc
UtilityLibrary.Win32.WindowsAPI
mssccprj.scc
Strong Keys
UtilityLibrary.Win32.WindowsAPI.csproj.user
UtilityLibrary.Win32.WindowsAPI.csproj.vspscc
vssver.scc
Win32
UtilityLibStrongKey.snk
vssver.scc
vssver.scc
using System;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Diagnostics;

namespace UtilityLibrary.Smtp
{ 
  /// <summary>
  /// Class for handling an SMTP connection.
  /// </summary>
  internal class SmtpConnection
  {
    #region Class members
    private TcpClient socket;
    private StreamReader reader;
    private StreamWriter writer;
    private bool connected;
    #endregion

    #region Class Constructor
    /// <summary>
    /// Create a new connection.
    /// </summary>
    internal SmtpConnection()
    {
      socket = new TcpClient();     
    }
    #endregion 

    #region Class methods
    /// <summary>
    /// Connection status.
    /// </summary>
    public bool Connected
    {
      get{return connected;}
    }

    /// <summary>
    /// Open connection with specified host and default port.
    /// </summary>
    /// <param name="host">Host name to connect to.</param>
    internal void Open(string host)
    {
      Open(host, 25);
    }
    
    /// <summary>
    /// Open connection to host on port.
    /// </summary>
    /// <param name="host">Host name to connect to.</param>
    /// <param name="port">Port to connect to.</param>
    internal void Open(string host, int port)
    {
      if(host == null || host.Trim().Length == 0 || port <= 0)
      {
        throw new System.ArgumentException("Invalid Argument found.");
      }
      socket.Connect(host, port);
      reader = new StreamReader(socket.GetStream(), System.Text.Encoding.ASCII);
      writer = new StreamWriter(socket.GetStream(), System.Text.Encoding.ASCII);
      connected = true;
    }
    
    /// <summary>
    /// Close connection.
    /// </summary>
    internal void Close()
    {
      reader.Close();
      writer.Flush();
      writer.Close();
      reader = null;
      writer = null;
      socket.Close();
      connected = false;
    }

    /// <summary>
    /// Send a command to the server.
    /// </summary>
    /// <param name="cmd">Command to send.</param>
    internal void SendCommand(string cmd)
    {
#if DEBUG
      Trace.WriteLine( cmd, "TO SMTP" );
#endif

      writer.WriteLine( cmd );
      writer.Flush();
    }

    /// <summary>
    /// Send data to the server. Used for sending attachments.
    /// </summary>
    /// <param name="buf">Data buffer.</param>
    /// <param name="start">Starting position in buffer.</param>
    /// <param name="length">Length to send.</param>
    internal void SendData(char[] buf, int start, int length)
    {
      writer.Write(buf, start, length);
    }

    /// <summary>
    /// Get the reply message from the server.
    /// </summary>
    /// <param name="reply">Text reply from server.</param>
    /// <param name="code">Status code from server.</param>
    internal void GetReply(out string reply, out int code)
    {
      reply = reader.ReadLine();

#if DEBUG
      Trace.WriteLine( reply, "FROM SMTP" );
#endif

      code = ( reply == null ) ? -1 : Int32.Parse(reply.Substring(0, 3));     
    }
    #endregion
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Oleksandr Kucherenko
CEO ArtfulBits Inc.
Ukraine Ukraine
Name:Kucherenko Oleksandr

Born:September 20, 1979

Platforms: Win32, Linux; - well known and MS-DOS; Win16; OS/2 - old time not touched;

Hardware: IBM PC

Programming Languages: Assembler (for Intel 80386); Borland C/C++; Borland Pascal; Object Pascal; Borland C++Builder; Delphi; Perl; Java; Visual C++; Visual J++; UML; XML/XSL; C#; VB.NET; T-SQL; PL/SQL; and etc.

Development Environments: MS Visual Studio 2001-2008; MS Visual C++; Borland Delphi; Borland C++Builder; C/C++ any; Rational Rose; GDPro; Together and etc.

Libraries: STL, ATL, WTL, MFC, NuMega Driver Works, VCL; .NET 1.0, 1.1, 2.0, 3.5; and etc.

Technologies: Client/Server; COM; DirectX; DirectX Media; BDE; HTML/DHTML; ActiveX; Java Servlets; DCOM; COM+; ADO; CORBA; .NET; Windows Forms; GDI/GDI+; and etc.

Application Skills: Databases - design and maintain, support, programming; GUI Design; System Programming, Security; Business Software Development. Win/Web Services development and etc.

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 25 Apr 2003
Article Copyright 2003 by Oleksandr Kucherenko
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid