By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,719 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,719 IT Pros & Developers. It's quick & easy.

MailMessage problem - Could not access 'CDO.Message' object.

P: n/a
Hello All,

I have a VB.Net app that needs to send mail. I have created a class for
building my e-mail, but keep getting the error (Could not access
'CDO.Message' object.) when trying to send it. I can successfully send an
e-mail when I use the CreateObject("CDO.Message") method, but it fails when
trying to send using VB.Net. My code is below, I have included three
different ways that I have tried it, and both VB.Net options fail, any help
will be greatly appreciated.

--
Thank you,

Anthony Fine
'// VB 6.0 - This works fine...
'***********************************************
Private Sub Form_Load()
Dim iNewMsg As Object
Set iNewMsg = CreateObject("CDO.Message")
iNewMsg.To = "so*****@there.com"
iNewMsg.From = "me@here.com"
iNewMsg.Subject = "Test"
iNewMsg.TextBody = "Hello..."
iNewMsg.Send
Set iNewMsg = Nothing
End Sub
'***********************************************

'// VB.Net - This fails...
'***********************************************
Imports System.Web.Mail
Imports System.Web.Mail.SmtpMail

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim iMsg As New MailMessage
Dim srv As SmtpMail
iMsg.To = "so*****@there.com"
iMsg.From = "me@here.com"
iMsg.BodyFormat = MailFormat.Text
iMsg.Body = "Testing..."
iMsg.Subject = "Test..."
srv.SmtpServer = "myServer"
srv.Send(iMsg)
End Sub
End Class
'***********************************************

'// VB.Net - This fails as well...
'***********************************************
Imports System.Web.Mail
Imports System.Web.Mail.SmtpMail

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newMail As New emailMessage
newMail.EmailTo = "so*****@there.com"
newMail.EmailFrom = "me@here.com"
newMail.EmailBodyFormat = MailFormat.Text
newMail.EmailBody = "Testing..."
newMail.EmailSubject = "Test..."
newMail.EmailServer = "myServer"
newMail.sendEmail()
newMail = Nothing
End Sub

End Class

Class emailMessage
Dim iMail As New MailMessage
Dim _to As String
Dim _from As String
Dim _server As SmtpMail
Dim _subject As String
Dim _body As String
Dim _bodyFormat As System.Web.Mail.MailFormat
Dim myServer As String

Public Property EmailTo() As String
Get
iMail.To = _to
End Get
Set(ByVal Value As String)
_to = Value
End Set
End Property

Public Property EmailFrom() As String
Get
iMail.From = _from
End Get
Set(ByVal Value As String)
_from = Value
End Set
End Property

Public Property EmailServer() As String
Get
_server.SmtpServer = myServer
End Get
Set(ByVal Value As String)
myServer = Value
End Set
End Property

Public Property EmailSubject() As String
Get
iMail.Subject = _subject
End Get
Set(ByVal Value As String)
_subject = Value
End Set
End Property

Public Property EmailBody() As String
Get
iMail.Body = _body
End Get
Set(ByVal Value As String)
_body = Value
End Set
End Property

Public Property EmailBodyFormat() As System.Web.Mail.MailFormat
Get
iMail.BodyFormat = _bodyFormat
End Get
Set(ByVal Value As System.Web.Mail.MailFormat)
_bodyFormat = Value
End Set
End Property

Public Sub sendEmail()
_server.Send(iMail)
End Sub
End Class
'***********************************************
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Cor
Hi Anthony,

Five messages below yours is an answer from Herfried as well as from Bernie
on a problem like this, maybe you can have a look at that?

Cor

I have a VB.Net app that needs to send mail. I have created a class for
building my e-mail, but keep getting the error (Could not access
'CDO.Message' object.) when trying to send it. I can successfully send an
e-mail when I use the CreateObject("CDO.Message") method, but it fails when trying to send using VB.Net. My code is below, I have included three
different ways that I have tried it, and both VB.Net options fail, any help will be greatly appreciated.

Nov 20 '05 #2

P: n/a
* "Anthony Fine" <an*****@sfa2000.com> scripsit:
I have a VB.Net app that needs to send mail. I have created a class for
building my e-mail, but keep getting the error (Could not access
'CDO.Message' object.) when trying to send it. I can successfully send an
e-mail when I use the CreateObject("CDO.Message") method, but it fails when
trying to send using VB.Net. My code is below, I have included three
different ways that I have tried it, and both VB.Net options fail, any help
will be greatly appreciated.


Does this sample work for you (notice that I forgot to specify the SMTP
server):

<http://www.mvps.org/dotnet/dotnet/samples/net/downloads/SendMail.zip>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Thanks for the responses, but sorry to report that it still does not work.
I get the same error message. The error message has to be a generic message
since I was able to successfully send mail using the
CreateObject("CDO.Message") method from VB 6.0, and the error I get is,
"Could not access 'CDO.Message' object." when trying it from VB.Net.

Thanks again,

Anthony

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:br************@ID-208219.news.uni-berlin.de...
* "Anthony Fine" <an*****@sfa2000.com> scripsit:
I have a VB.Net app that needs to send mail. I have created a class for
building my e-mail, but keep getting the error (Could not access
'CDO.Message' object.) when trying to send it. I can successfully send an e-mail when I use the CreateObject("CDO.Message") method, but it fails when trying to send using VB.Net. My code is below, I have included three
different ways that I have tried it, and both VB.Net options fail, any help will be greatly appreciated.


Does this sample work for you (notice that I forgot to specify the SMTP
server):

<http://www.mvps.org/dotnet/dotnet/samples/net/downloads/SendMail.zip>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.