Link to home
Start Free TrialLog in
Avatar of mte01
mte01Flag for Lebanon

asked on

Sending e-mail in Console App.

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 asp.net application):

            MailMessage newMail = new MailMessage();
            newMail.To = ToEmail;
            newMail.From = "mohamad_majzoub_cme@yahoo.com";
            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("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
            newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sendemailusername);
            newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", sendemailpassword );
            newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
            newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", SmtpServer);
            newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 50);
            newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);

          SmtpMail.SmtpServer = SmtpServer;

            SmtpMail.Send(newMail);
Avatar of dstanley9
dstanley9

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.
Avatar of mte01

ASKER

>>dstanley9

The inner exception is "The transport failed to connect to the server"
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mte01

ASKER

>>dstanley9

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