Click here to Skip to main content
15,898,982 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In localhost it works fine,
In live it provide Error:

Error msg:
Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed


help me my code is:

public ActionResult Email(RegInfo registration)
{
try
{
var from = System.Configuration.ConfigurationManager.AppSettings["UserName"];
var smtpHost = System.Configuration.ConfigurationManager.AppSettings["Host"];
var mailPwd = System.Configuration.ConfigurationManager.AppSettings["MailPwd"];
var smtpPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"]);
var callBackUrl = System.Configuration.ConfigurationManager.AppSettings["CallBackUrl"] + registration.ROLEBYID;
var msg = new MailMessage(from, registration.EMAIL) { Subject = "Verify Your Account" };
var Body = string.Format("Hi {0}
Your Account Registerd.
Your Id is :{1}
Please confirm your account by clicking <a href=\"{2}\">here", registration.NAME, registration.ROLEBYID, callBackUrl);
msg.Body = Body;
msg.IsBodyHtml = true;
var smtp = new SmtpClient()
{
Host = smtpHost,
Port = smtpPort,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(from, mailPwd), EnableSsl = true
};
smtp.Send(msg);
return RedirectToAction("Create");



}
catch (Exception ex)
{
TempData["error"] = ex.Message;
return RedirectToAction("Create");
}
}

What I have tried:

Changed ssl to false , but not working
Posted
Updated 19-May-17 3:22am
Comments
F-ES Sitecore 19-May-17 7:57am    
If it works locally but not on live then the issue is with the live configuration, maybe with your trust level or general access rights. Contact your webhost and see what they say.
Member 11255203 19-May-17 8:05am    
thank you

1 solution

There are several things that can cause this. This is the first google search result: c# - SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission' - Stack Overflow[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900