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 co
mpany walls. When the e-mail is send on some one in my company it works perf
ect.
I think it is a relay issue. Our system administrator will not allow relayin
g.
In the ASP.Net web.config file I let the web application impersonate a speci
fic 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 r
elaying 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(Object obj,
String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailM
essage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at NCR
2.SendMail.btSend_Click(Obj
ect 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 c
ulture, String[] namedParameters) at System.RuntimeType.InvokeMember(String
name, BindingFlags invokeAt
tr, Binder binder, Object target, Object[] args, ParameterModifier[] modifie
rs, CultureInfo culture, String[] namedParameters) at System.Web.Mail.LateBo
undAccessHelper.CallMethod(Object obj, String methodName, Object[] args)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 cal
l 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 pe
rfect.
> I think it is a relay issue. Our system administrator will not allow relay
ing.
> In the ASP.Net web.config file I let the web application impersonate a spe
cific 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(Object 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_Clic
k(O
bject sender, EventArgs e) in C:\Inetpub\wwwroot\NCR2\SendMail.aspx.vb:line 79d">
> Message: Exception has been thrown by the target of an invocation.
> Source: mscorlib
> StackTrace: at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invok
eAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String
[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags inv
oke
Attr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureIn
fo 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 G
Challengeshttp://www.osix.net
--
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...
0 comments:
Post a Comment