Click here to Skip to main content
15,894,540 members
Articles / Programming Languages / C#

A .NET Wizard control

Rate me:
Please Sign up or sign in to vote.
4.86/5 (89 votes)
24 Apr 2003CPOL7 min read 666.4K   8.7K   216  
A .NET Wizard control for the VS.IDE and client apps
/*
 * SmtpEmailer : A class/library for sending SMTP messages.
 * Provided by Steaven Woyan swoyan@hotmail.com
 * This package is provided without any warranty.
 * By using this package you agree that the provider makes no guarantee of use
 * and shall not be held liable or accountable for use of this software, even if it
 * fails to work properly.
 * 
 * Parts of this package include logic/code design from PJ Naughter's C++ SMTP package
 * located at http://www.naughter.com/smpt.html.  This link is provided for documentation
 * purposes and is not meant to imply his use/acknowledgement/approval of this package.
 * 
 * This package is provided with source and is free for use for any reason except that
 * it may not be sold or re-packaged by itself.
 * 
 */
using System;

namespace UtilityLibrary.Smtp
{
  /// <summary>
  /// For use in SmtpAttachment.
  /// </summary>
  public enum AttachmentLocation
  {
    /// <summary>
    /// Send as regular attachment.
    /// </summary>
    Attachment = 0,
    /// <summary>
    /// Send as MIME inline (for html images, etc).
    /// </summary>
    Inline = 1
  }

  /// <summary>
  /// Class for holding an attachment's information.
  /// </summary>
  public class SmtpAttachment
  {
    internal static int inlineCount;
    internal static int attachCount;
    internal AttachmentLocation location;
    /// <summary>
    /// File to send.
    /// </summary>
    public string FileName;
    /// <summary>
    /// Content type of file (application/octet-stream for regular attachments).
    /// </summary>
    public string ContentType;
    
    /// <summary>
    /// Where to put the attachment.
    /// </summary>
    public AttachmentLocation Location
    {
      get {return location;}
      set
      {       
        if(value == AttachmentLocation.Attachment)
        {
          ++attachCount;
        }
        else if(value == AttachmentLocation.Inline)
        {
          ++inlineCount;
        }
        else
        {
          throw new Exception("Invalid location.");
        }
        location = value;
      }
    }

    /// <summary>
    /// Default constructor.
    /// </summary>
    public SmtpAttachment(){}

    /// <summary>
    /// Constructor for passing all information at once.
    /// </summary>
    /// <param name="fileName">File to send.</param>
    /// <param name="contentType">Content type of file (application/octet-stream for regular attachments.)</param>
    /// <param name="location">Where to put the attachment.</param>
    public SmtpAttachment(string fileName, string contentType, AttachmentLocation location)
    {
      this.FileName = fileName;
      this.ContentType = contentType;
      this.Location = location;
    }

    /// <summary>
    /// Shortcut constructor for passing regular style attachments.
    /// </summary>
    /// <param name="filename">File to send.</param>
    public SmtpAttachment(string filename) : this(filename, "application/octet-stream", AttachmentLocation.Attachment)
    {     
    }

    /// <summary>
    /// Show this attachment.
    /// </summary>
    /// <returns>The file name of the attachment.</returns>
    public override string ToString()
    {
      return FileName;
    }
  }

  /// <summary>
  /// List of SMTP reply codes.
  /// </summary>
  internal enum SmtpResponseCodes
  {
    SystemStatus = 211,
    Help = 214,
    Ready = 220,
    ClosingChannel = 221,
    RequestCompleted = 250,
    UserNotLocalOk = 251,
    StartInput = 354,
    ServiceNotAvailable = 421,
    MailBoxUnavailable = 450,
    RequestAborted = 451,
    InsufficientStorage = 452,
    Error = 500,
    SyntaxError = 501,
    CommandNotImplemented = 502,
    BadSequence = 503,
    CommandParameterNotImplemented = 504, 
    MailBoxNotFound = 550,
    UserNotLocalBad = 551,
    ExceededStorage = 552,
    MailBoxNameNotValid = 553,
    TransactionFailed = 554
  }
}

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)


Written By
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.

Comments and Discussions