MailMessage problem - Could not access 'CDO.Message' object.
Messages   Related Types
This message was discovered on microsoft.public.dotnet.faqs.

Post a new message to this list...

Anthony Fine
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 succesfully 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 = "Click here to reveal e-mail address"
iNewMsg.From = "Click here to reveal e-mail address"
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 = "Click here to reveal e-mail address"
iMsg.From = "Click here to reveal e-mail address"
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 = "Click here to reveal e-mail address"
newMail.EmailFrom = "Click here to reveal e-mail address"
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
'***********************************************

Reply to this message...
 
    
Mike Bulava
Make sure you are setting the SMTP server property to a Valid SMTP Server
that doesn't require authentication. Or you will have to install IIS on to
your workstation..

"Anthony Fine" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Anthony Fine
Mike,

Thanks for the response. I was able to successfully send an e-mail using VB
6.0 by using the CreateObject method. If the SMTP server was the problem,
wouldn't that prevent me from sending e-mail from VB 6.0 as well?

Thanks,
Anthony

"Mike Bulava" <Click here to reveal e-mail address> wrote in message
news:O3Lo%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Richard Waddell
Sorry, these messages are out of sequence, forgot the CAPTCHA thing the first time - when did that start?

Anyway, if the smtp server is not running, I find that SmtpMail.Send fails with an exception. CDO.Message, used directly in a classic asp page, places the message in the mailroot/pickup folder where it will be sent out when the smtp server starts again.

As a workaround, I'm trying to use CDO.Message from an asp.net page. I can create an object of course, but I haven't figured out how to reference the CDO.Message properties and methods. Reflection will probably do it, but I still have to figure out why.

Regards,
Richard Waddell
Reply to this message...
 
    
Jure Spik
I have sucessfully sent mail using >>
<%@ Page Language="JScript" %>
<%@ import Namespace="System.Web.Mail" %>

<HTML>
<head>
<script runat='server'>
function Page_Load() {
var Mailer : MailMessage = new MailMessage();
Mailer.From = "from@.net";
Mailer.To = "addresee@.net";
Mailer.Subject = "subject";
Mailer.Body = "body";

try {
SmtpMail.SmtpServer = "smtp.some.smtp.server";
SmtpMail.Send(Mailer);
mStatus.Text += "Mail sent to " + Mailer.To + "<br />";
} catch (e : Exception) {
mStatus.Text += ("<p>Could not send mail because:<br /><div
style='font-size:70%;'>" + e.ToString() + "</div><br />If you think this is
an error contact the administrator.</p>");
}
Mailer = null;
}
</script>
</head>
<body>
<asp:Label runat='server' id='mStatus' />
</body>
</HTML>

Reply to this message...
 
    
Jan Veitch
It may not apply directly to your issue above, but my resolution for the error message was to open a telnet window to the SMTP server and manually input the mail parameters using the standard SMTP syntax. In my case, I found that the ISP had implemented SMTP security in between my debug builds. This was causing the mail session to error and in turn cause the above exception. I had the same error while using the IIS SMTP server in XP Pro, and found that the error was being cause by IIS configuration. The SMTP server was not allowing relay - from any IP or address. Again, this was a result of my reconfiguration of IIS between builds. So, in both cases, Telnetting to the server and entering the parameters that my code was sending manually quickly illuminated the source of the error.

----
From: Jan Veitch
Reply to this message...
 
 
System.EventArgs
System.Object
System.Web.Mail.MailFormat
System.Web.Mail.MailMessage
System.Web.Mail.SmtpMail
System.Windows.Forms.Form




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com