Sending e-mail in Console App.

Posted on 2007-08-06
Last Modified: 2010-04-16
Hey experts,

 I am trying to send an e-mail using a console application in .NET 1.1, and I am getting the following exception: "Could not access 'CDO.Message' object" (Although I have added the System.Web dll to the project)
at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.SmtpMail.Send(MailMessage message)

The code is as follows (working fine in an application):

            MailMessage newMail = new MailMessage();
            newMail.To = ToEmail;
            newMail.From = "";
            string ccList = "";
            for (int i = 0; i < CcEmail.Length; i++)
                ccList += CcEmail[i].ToString() + ", ";
            newMail.Cc = ccList.Substring(0, ccList.Length - 2);

            if (Html)
                newMail.BodyFormat = MailFormat.Html;

            newMail.Subject = Subject;
            newMail.Body = Body;

            newMail.Fields.Add("", 1);
            newMail.Fields.Add("", sendemailusername);
            newMail.Fields.Add("", sendemailpassword );
            newMail.Fields.Add("", 2);
            newMail.Fields.Add("", SmtpServer);
            newMail.Fields.Add("", 50);
            newMail.Fields.Add("", 25);

          SmtpMail.SmtpServer = SmtpServer;

Question by:mte01
    LVL 25

    Expert Comment

    That's a generic error message from CDO, which is the COM part of the mail component.  Catch the exception and look at the InnerException to get a more detailed message.
    LVL 3

    Author Comment


    The inner exception is "The transport failed to connect to the server"
    LVL 25

    Accepted Solution

    Then something is not allowing you to connect to the email server.  Can you ping the IP address?  Are there any firewalls in your way?  Does it allow relaying?
    LVL 3

    Author Comment


    You were right; I used the local mail server; many thanks for your help!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now