Link to home
Start Free TrialLog in
Avatar of nirmalas
nirmalas

asked on

Error while sending mail

Hi,

I have a ASPX which sends mails to users.
The code is :
try
{
     MailMessage mailMsg = new MailMessage();
     mailMsg.To = strToAddress;
     mailMsg.From = strFromAddress;
     mailMsg.Subject = strSubject;
     mailMsg.BodyFormat = MailFormat.Text;
     mailMsg.Body=strMessageBody;    
     SmtpMail.Send(mailMsg);
     return "Message was successfully sent.";
}
catch(Exception ex)
{
     return ex.InnerException + ex.StackTrace + ex.Message;
}
               
The stack trace is given below:
 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.UnauthorizedAccessException: Access is denied. --- End of inner exception stack trace --- 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(Object obj, String methodName, Object[] args) 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 WWSFE.Util.SendEmail(String strToAddress, String strFromAddress, String strSubject, String strMessageBody) in c:\inetpub\wwwroot\wws\classfile\wwsfe.cs:line 2274Could not access 'CDO.Message' object.
 
How to overcome this problem.

Thanks in advance,
Nirmala S.

ASKER CERTIFIED SOLUTION
Avatar of Yog
Yog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Yog
Yog

its for security reasons, you have to specify this , i assume SMTP is configured setting localhost to 121.0.0.1 blah blah
I think you should configure the SmtpServer to a specific Ip.
I believe that will solve the problem.
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange