mte01
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.LateBoundA ccessHelpe r.CallMeth od(Object obj, String methodName, Object[] args)
at System.Web.Mail.CdoSysHelp er.Send(Ma ilMessage message)
at System.Web.Mail.SmtpMail.S end(MailMe ssage 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);
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.LateBoundA
at System.Web.Mail.CdoSysHelp
at System.Web.Mail.SmtpMail.S
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
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);
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.
ASKER
>>dstanley9
The inner exception is "The transport failed to connect to the server"
The inner exception is "The transport failed to connect to the server"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>dstanley9
You were right; I used the local mail server; many thanks for your help!
You were right; I used the local mail server; many thanks for your help!