problem ved afsendelse af mail..
System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.Line 43: {
Line 44:
Line 45: SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
Line 46: //to authenticate we set the username and password properites on the SmtpClient
Line 47: sc.EnableSsl = true;
Jeg får denne fejl ved afsendelse af mail. Det virker fint lokalt men ikke efter jeg uploader. Nogen der kan hjælpe?
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
//to authenticate we set the username and password properites on the SmtpClient
sc.EnableSsl = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = new NetworkCredential("brugernavn", "kodeord");
StringBuilder sb = new StringBuilder();
MailMessage msg = null;
sb.Append("***. " + "\n\n");
sb.Append("Navn: " + txtName.Text + "\n");
sb.Append("Mail: " + txtMail.Text + "\n");
sb.Append("tlf.nr. : " + txtPhone.Text + "\n\n");
if (RadioButton1.Checked == true)
sb.Append("****? : " + RadioButton1.Text + "\n");
if (RadioButton2.Checked == true)
sb.Append("*****? : " + RadioButton2.Text + "\n\n");
;
try
{
msg = new MailMessage(txtMail.Text, "mail@hotmail.com", "support@support.com", sb.ToString());
sc.Send(msg);
txtName.Text = "";
txtPhone.Text = "";
txtMail.Text = "";
Response.Redirect("MailRecieved.aspx");
}
catch (Exception err)
{
// something bad happened
Response.Write(err.Message);
}
finally
{
if (msg != null)
{
msg.Dispose();
}
}