Click here to Skip to main content
15,896,118 members
Articles / Programming Languages / C#

IMAP and POP3 Clients in C#

Rate me:
Please Sign up or sign in to vote.
4.67/5 (21 votes)
28 Sep 2012CPOL1 min read 259.1K   16.6K   48  
IMAP & POP3 Clients C#. A library for intuitive ease of use of these two protocols.
using System;
using System.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.SMTP.Client
{
    /// <summary>
    /// SMTP client exception.
    /// </summary>
    public class SMTP_ClientException : Exception
    {
        private SMTP_t_ReplyLine[] m_pReplyLines  = null;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="responseLine">SMTP server response line.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>responseLine</b> is null.</exception>
        public SMTP_ClientException(string responseLine) : base(responseLine.TrimEnd())
        {
            if(responseLine == null){
                throw new ArgumentNullException("responseLine");
            }

            m_pReplyLines = new SMTP_t_ReplyLine[]{SMTP_t_ReplyLine.Parse(responseLine)};
        }

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="replyLines">SMTP server error reply lines.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>replyLines</b> is null reference.</exception>
        public SMTP_ClientException(SMTP_t_ReplyLine[] replyLines) : base(replyLines[0].ToString().TrimEnd())
        {
            if(replyLines == null){
                throw new ArgumentNullException("replyLines");
            }

            m_pReplyLines = replyLines;            
        }


        #region Properties Implementation

        /// <summary>
        /// Gets SMTP status code.
        /// </summary>
        [Obsolete("Use property 'ReplyLines' insead.")]
        public int StatusCode
        {
            get{ return m_pReplyLines[0].ReplyCode; }
        }

        /// <summary>
        /// Gets SMTP server response text after status code.
        /// </summary>
        [Obsolete("Use property 'ReplyLines' insead.")]
        public string ResponseText
        {
            get{ return m_pReplyLines[0].Text; }
        }

        /// <summary>
        /// Gets SMTP server error reply lines.
        /// </summary>
        public SMTP_t_ReplyLine[] ReplyLines
        {
            get{ return m_pReplyLines; }
        }

        /// <summary>
        /// Gets if it is permanent SMTP(5xx) error.
        /// </summary>
        public bool IsPermanentError
        {
            get{
                if(m_pReplyLines[0].ReplyCode >= 500 && m_pReplyLines[0].ReplyCode <= 599){
                    return true;
                }
                else{
                    return false;
                }
            }
        }

        #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)


Written By
Software Developer (Senior) D.Net Solution
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions