I am trying to send an email from an ASP.NET application and get the error "Could not create 'CDO.Message' object"
It seems to be some permission error and unfortunately cannot figure it out, hence this post. I tested the same code in a VB.NET application and it works fine and sends the email. The error occurs in the ASP.NET page.
Below is the code that I am using to send the email, and I have also imported the System.Web.Mail class

Dim myMail As New MailMessage
 
myMail.From = "[EMAIL="mymails@abc.com"]mymails@abc.com[/EMAIL]"
myMail.To = "[EMAIL="artee@abc.com"]artee@abc.com[/EMAIL]"
myMail.Subject = "this is a test email."
myMail.Body = "Some text goes here"
SmtpMail.SmtpServer = "localhost"
Try
SmtpMail.Send(myMail)
Catch ex As Exception
Response.Write(("The following exception occurred: " + ex.ToString()))
'check the InnerException
While Not (ex.InnerException Is Nothing)
Response.Write("--------------------------------")
Response.Write(("The following InnerException reported: " + ex.InnerException.ToString()))
ex = ex.InnerException
End While
End Try

The Error displayed on the ASPX page is as below
'**********************************
The following exception occurred: System.Web.HttpException: Could not create 'CDO.Message' object. at System.Web.Mail.LateBoundAccessHelper.get_LateBoundType() at System.Web.Mail.LateBoundAccessHelper.CreateInstance() at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at TestEmails.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\TestEmails\MainPage.aspx.vb:line 40
'**********************************

Can you please help. I have been struggling with this the past couple of days trying to set permissions and registering the cdosys.dll, but nothing seems to work
Thanks
- Artee

Recommended Answers

All 2 Replies

do you have a mail server on your local machine? you are calling the smtp server on localhost but i suspect the service isnt installed and running. use a known smtp server. then add .net credentials to the smtpmail.

I would also use the system.net.mail namespace rather than the old smtp namespace if you have .net 2 on your pc

I know it is probably too late to help you, but someone else may benefit from this question.
The format is quite different for the cdosys message in asp.net with VB. There is a link here that is good for explaining system.net.mail use in different languages. This is compatible with windows 2003, not 2000. W2K uses the deprecated system.web.mail format.

'create the mail message
Dim mail As New MailMessage()

'set the addresses
mail.From = New MailAddress("me@mycompany.com")
mail.To.Add("you@yourcompany.com")

'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"

'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.