Hello friends, I am working on my code with a method that sends mail from a Gmail account. This method was published here in aspsnippets.com, and I use it as a reference.
Error Message: System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission' failed.
but it throws the following error, and when I have running on my hosting server.
this is the code
using (MailMessage mm = new MailMessage("sender@gmail.com", txtEmail.Text))
{
mm.Subject = "Account Activation";
string body = "Hello " + txtUsername.Text.Trim() + ",";
body += "<br /><br />Please click the following link to activate your account";
body += "<br /><a href = '" + Request.Url.AbsoluteUri.Replace("CS.aspx", "CS_Activation.aspx?ActivationCode=" + activationCode) + "'>Click here to activate your account.</a>";
body += "<br /><br />Thanks";
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("sender@gmail.com", "<password>");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
this is my error
Thank you for your help.
Thank you, Regards.