473,228 Members | 1,662 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,228 software developers and data experts.

SmtpMail.Send - Exception: "Could not access 'CDO.Message' object"

Hi
I am writing a ASP.NET web application that must sent some e-mails.

I get the exception “Could not access 'CDO.Message' object” when I call SmtpMail.Send. This only happens when I send e-mail addresses out side my company walls. When the e-mail is send on some one in my company it works perfect.

I think it is a relay issue. Our system administrator will not allow relaying.

In the ASP.Net web.config file I let the web application impersonate a specific user that has a mail account on our mail server:

<identity impersonate="true" userName="MyDon\MyUserName" password="zzzz" />

The web server and the mail server are two different physical computers.

I have two questions:
1) How can I fix the problem?
2) Is it a relay issue? If yes, what can I do to fix it? Is it OK to allow relaying on a mail server?

Below you can se my code and the exceptions

Regards
Jens

Here you can see my code

Try

Mail.From = tbFrom.Text
Mail.To = tbTo.Text
Mail.Subject = tbSubject.Text
Mail.Body = tbMessage.Text

Dim SmtpMail As Mail.SmtpMail
SmtpMail.SmtpServer = "MyMailServerName"
SmtpMail.Send(Mail)

Catch ex As Exception

While (Not ex.InnerException Is Nothing)
Response.Write( _
"<b>Message:</b> " & ex.Message & "<br>" & _
"<b>Source:</b> " & ex.Source & "<br>" & _
"<b>StackTrace:</b> " & ex.StackTrace & "<br>" & _
"<b>HelpLink:</b> " & ex.HelpLink & "<br>" & _
"<b>UserName:</b> " & User.Identity.Name & "<br><br>")
ex = ex.InnerException
End While
End Try

Message: Could not access 'CDO.Message' object.
Source: System.Web
StackTrace: at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at NCR2.SendMail.btSend_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\NCR2\SendMail.aspx.vb:line 79

Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
StackTrace: at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args)

Nov 18 '05 #1
3 9221
bb
Jens wrote:
Hi
I am writing a ASP.NET web application that must sent some e-mails.

I get the exception “Could not access 'CDO.Message' object” when I call SmtpMail.Send. This only happens when I send e-mail addresses out side my company walls. When the e-mail is send on some one in my company it works perfect.

I think it is a relay issue. Our system administrator will not allow relaying.

In the ASP.Net web.config file I let the web application impersonate a specific user that has a mail account on our mail server:

<identity impersonate="true" userName="MyDon\MyUserName" password="zzzz" />

The web server and the mail server are two different physical computers.

I have two questions:
1) How can I fix the problem?
2) Is it a relay issue? If yes, what can I do to fix it? Is it OK to allow relaying on a mail server?

Below you can se my code and the exceptions

Regards
Jens

Here you can see my code

Try

Mail.From = tbFrom.Text
Mail.To = tbTo.Text
Mail.Subject = tbSubject.Text
Mail.Body = tbMessage.Text

Dim SmtpMail As Mail.SmtpMail
SmtpMail.SmtpServer = "MyMailServerName"
SmtpMail.Send(Mail)

Catch ex As Exception

While (Not ex.InnerException Is Nothing)
Response.Write( _
"<b>Message:</b> " & ex.Message & "<br>" & _
"<b>Source:</b> " & ex.Source & "<br>" & _
"<b>StackTrace:</b> " & ex.StackTrace & "<br>" & _
"<b>HelpLink:</b> " & ex.HelpLink & "<br>" & _
"<b>UserName:</b> " & User.Identity.Name & "<br><br>")
ex = ex.InnerException
End While
End Try

Message: Could not access 'CDO.Message' object.
Source: System.Web
StackTrace: at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at NCR2.SendMail.btSend_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\NCR2\SendMail.aspx.vb:line 79

Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
StackTrace: at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args)


I used to get that message and wonder why the hell emails failed..

do this, to get the real error message of why the mail wasnt sent like
this ...

catch(Exception e)
{
e = e.GetBaseException();
log.Error("Error sending email via Server - + e.Message);
}

I now use both OpenSmtp and System.Web.Mail support in our applications
so that it can be configured on site. We find that the OpenSmtp library
provides much clearer diagnostics than CDONTS

Of course, this wont solve your problem, but may get you a meaningfull
error message ;-)

bb
--
------------------------
Think your smart?
Prove your programming power @ the OSI Geek Challenges
http://www.osix.net
------------------------
Nov 18 '05 #2
I have found that this problem is sometimes caused by SMTP Server not
being set properly.

Try adding this line immediately before the .Send() line in your code:

SmtpMail.Server = "localhost";

(or preferably something not hardcoded:
SmtpMail.Server = ConfigurationSettings.AppSettings["SmtpServer"];
)
2) Is it a relay issue? If yes, what can I do to fix it?
Is it OK to allow relaying on a mail server?


No... If you're sending from a company e-mail address, then your server
should should regard the messages as coming from a local account and it
will deliver it. If you have to send messages from a different address,
then ensure that you limit relaying to the IP range of your internal
network. Do not under any circumstances allow external clients to relay
via your server - you will be RBL blacklisted and will find it very
difficult to send e-mail to anyone after that.

Nick...
Nov 18 '05 #3
Thank you, your answer leads me in the right direction. The solution to my
relay problem was:

I change the security settings of the mail server. The mail server now
allows relaying when the server that tries to relay is my web server
computer. And now it works :-)

In Exchange this is done as follows:

1) Select: Adm Groups | <Your mail group > | Servers | <Your Exchange
server> | Protocols | SMTP | <Your Web server>
2) Select the tab Access
3) Press Relay
4) Add the IP address to the web server
Regards,
Jens
"Nick Gilbert" wrote:
I have found that this problem is sometimes caused by SMTP Server not
being set properly.

Try adding this line immediately before the .Send() line in your code:

SmtpMail.Server = "localhost";

(or preferably something not hardcoded:
SmtpMail.Server = ConfigurationSettings.AppSettings["SmtpServer"];
)
> 2) Is it a relay issue? If yes, what can I do to fix it?
> Is it OK to allow relaying on a mail server?


No... If you're sending from a company e-mail address, then your server
should should regard the messages as coming from a local account and it
will deliver it. If you have to send messages from a different address,
then ensure that you limit relaying to the IP range of your internal
network. Do not under any circumstances allow external clients to relay
via your server - you will be RBL blacklisted and will find it very
difficult to send e-mail to anyone after that.

Nick...

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: M D | last post by:
For the code see MS knowledge base #310273. All I did was comment out the parts for adding an attachment and put real values in for smtpServer & email addresses. For the SmtpServer I used my...
1
by: Kamal | last post by:
I am trying to send mail through smtp. smtp service is running on my machine. But every time during the smtpmail.send(msg) call gives "Could not access 'CDO.Message' object." error. Could some...
3
by: Jibu | last post by:
Hi I am using SmtpMail class for mail sending. I could able to send mail using my mailse server to our LAN. But when I tried external addresses it showed the exception Message "Could not...
1
by: Jens Øster | last post by:
Hi I am writing a ASP.NET web application that must sent some e-mails. I get the exception “Could not access 'CDO.Message' object” when I call SmtpMail.Send. This only happens when I send...
4
by: Liz Patton | last post by:
Here's the exception: System.Exception: Unable to send mail: Could not access 'CDO.Message' object. ---> System.Web.HttpException: Could not access 'CDO.Message' object. --->...
2
by: chuckdfoster | last post by:
I am getting a "Could Not Access CDO.Message Object" Error when I try to use the following code to send an email via ASP.NET. When I run this on one machine it works, on another one it doesn't. ...
1
by: Jason | last post by:
I am trying to send mail via SMTP, using VB.NET on XP. I keep getting this error: "Could not access 'CDO.Message' object." (I can send mail fine via VB6, using CDONTS.) I have added a reference...
4
farooqbob
by: farooqbob | last post by:
When i sending a HTML mail I getting this Erro "could not access "CDO.Message" object" How can i fix this problem
1
by: ashish | last post by:
Dim oCon Err.Clear Set oCon = Server.CreateObject("ADODB.Connection") If Err.Number = 0 Then '// '// Open an ADODB.Connection to the folder URL '// oCon.Provider = "ExOLEDB.DataSource"
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.