Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

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);
0
mte01
Asked:
mte01
  • 2
  • 2
1 Solution
 
dstanley9Commented:
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.
0
 
mte01Author Commented:
>>dstanley9

The inner exception is "The transport failed to connect to the server"
0
 
dstanley9Commented:
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?
0
 
mte01Author Commented:
>>dstanley9

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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now