Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Windows App connection error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mr. Murad Jamal - 26 Jul 2006 06:35 GMT
There's a vb.net 2005 windows app that sends out emails, it works fine, but
sometimes it gives these errors:

1)System.Runtime.InteropServices.COMException (0x80040212): The transport
lost its connection to the server.

2) System.Runtime.InteropServices.COMException (0x80040213): The transport
failed to connect to the server.

What's the main reason behind these errors.

Thank you so much in advance.
simida - 26 Jul 2006 07:25 GMT
The possible reason may be that it could not access 'CDO.Message'
object.

/*------------------  Exception details-----------------------*/
Could not access 'CDO.Message' object. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.Runtime.InteropServices.COMException (0x80040212): The transport
lost its connection to the server.

I used thecode as follows to send mail, and it works fine at all times.
Enjoy it.

/*---------------------------------------------------- Code
-------------------------------------------*/
               /// <summary>
    /// MailHandler class for sending mail notification.
    /// </summary>
    public class MailHandler
    {
        #region "Private members"
        // Private variable members

        private string _accountName                = string.Empty;        // Account name from
SMTP server.
        private string _accountPwd                = string.Empty;        // Account password
from SMTP server.
        private string _from                    = string.Empty;        // Sender Email address.
        private string _to                        = string.Empty;        // Recipients Email address.
        private string _subject                    = string.Empty;        // Subject of the mail.
        private string _body                    = string.Empty;        // Body of the mail.
        private string _mailServer               = string.Empty;        // Email server
name.

        private bool _isRequireAuthentication   = false;            // Authentication.

        private MailFormat _mailFormat  = MailFormat.Html;    // Email format.

        #endregion

        #region "Public properties"

        /// <summary>
        /// AccountName property for setting or getting account name from
SMTP server.
        /// </summary>
        public string AccountName
        {
            get { return this._accountName;}
            set { this._accountName = value;}
        }

        /// <summary>
        /// AccountPwd property for setting or getting account password from
SMTP server.
        /// </summary>
        public string AccountPwd
        {
            get { return this._accountPwd;}
            set { this._accountPwd = value;}
        }

        /// <summary>
        /// IsRequireAuthentication property for setting or getting
authentication.
        /// </summary>
        public bool IsRequireAuthentication
        {
            get { return this._isRequireAuthentication;}
            set { this._isRequireAuthentication = value;}
        }
        /// <summary>
        /// From property for setting or getting sender Email address.
        /// </summary>
        public string From
        {
            get { return this._from;}
            set { this._from = value;}
        }

        /// <summary>
        /// To property for setting or getting recipients Email address.
        /// </summary>
        public string To
        {
            get { return this._to;}
            set { this._to = value;}
        }

        /// <summary>
        /// Subject property for setting or getting the subject of the Email.

        /// </summary>
        public string Subject
        {
            get { return this._subject;}
            set { this._subject = value;}
        }

        /// <summary>
        /// Body property for setting or getting the body of the Email.
        /// </summary>
        public string Body
        {
            get { return this._body;}
            set { this._body = value;}
        }

        /// <summary>
        /// MailServer property for setting or getting email server name.
        /// </summary>
        public string MailServer
        {
            get { return this._mailServer;}
            set { this._mailServer = value;}
        }
        #endregion

        #region "Constructors"
        /// <summary>
        /// Default constructor
        /// </summary>
        public MailHandler()
        {
            this._from         = string.Empty;
            this._to         = string.Empty;
            this._subject     = string.Empty;
            this._body         = string.Empty;
            this._mailServer  = string.Empty;
            this._mailFormat  = MailFormat.Html;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="from">Sender Email address</param>
        /// <param name="to">Recipients Email address</param>
        /// <param name="subject">Subject of the mail</param>
        /// <param name="body">Body of the mail</param>
        /// <param name="mailServer">Email server name</param>
        public MailHandler(string from,string to,string subject,string body,
            string mailServer,string accountName,string accountPwd,bool
isRequireAuthentication)
        {
            this._from                        = from;
            this._to                        = to;
            this._subject                    = subject;
            this._body                        = body;
            this._mailServer                = mailServer;
            this._mailFormat                = MailFormat.Html;
            this._accountName                = accountName;
            this._accountPwd                = accountPwd;
            this._isRequireAuthentication    = isRequireAuthentication;
        }
        #endregion

        #region "Public functions"
        /// <summary>
        /// SendMail method is used to send email.
        /// </summary>
        public bool SendMail()
        {
            bool isSended = false;
            try
            {
                // Construct Email content.
                MailMessage notificationMail    = new MailMessage();
                notificationMail.From            = this._from;
                notificationMail.To                = this._to;
                notificationMail.Subject        = this._subject;
                notificationMail.Priority        = MailPriority.Normal;
                notificationMail.BodyFormat        = this._mailFormat;
                notificationMail.Body            = this._body;
                // Set SMTP server address.
                SmtpMail.SmtpServer                = this._mailServer;

                // Set authentication.
                if (this._isRequireAuthentication)
                {
                    notificationMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1");
                    // Set Account information from SMTP server.
                    notificationMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",this._accountName);
                    notificationMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",this._accountPwd);
                }

                // Send mail.
                SmtpMail.Send(notificationMail);
                isSended = true;
            }
            catch (Exception e)
            {
                isSended = false;
                throw new Exception(e.Message,e);
            }
            return isSended;
        }
        #endregion
    }

> There's a vb.net 2005 windows app that sends out emails, it works fine, but
> sometimes it gives these errors:
[quoted text clipped - 8 lines]
>
> Thank you so much in advance.
Mr. Murad Jamal - 27 Jul 2006 19:42 GMT
thank you so much i appreciate it.

> The possible reason may be that it could not access 'CDO.Message'
> object.
[quoted text clipped - 208 lines]
> >
> > Thank you so much in advance.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.