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

Hello All,

I have hosted site to go daddy.and trying to send mail using smtp client but it fires error

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

find attach code snippet.

thanx in advance
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
public void SendAutoEmail(SendMailTemplatePro _clsObjSendMailTemplatePro) {
           try {
                string SmtpServer; //= System.Configuration.ConfigurationManager.AppSettings["SmtpServer"].ToString();
                string SmtpPassword; //= System.Configuration.ConfigurationManager.AppSettings["SmtpPassword"].ToString();
                string SmtpPort; //= System.Configuration.ConfigurationManager.AppSettings["SmtpPort"].ToString();
                string str_from_address; //= System.Configuration.ConfigurationManager.AppSettings["mailaddress"].ToString();
                string str_to_address;
                string str_cc_address="";
                string str_bcc_address="";


                Hashtable templateVars = new Hashtable();
                templateVars.Add("EmailText", _clsObjSendMailTemplatePro.Body);
           
                Parser parser = new Parser(System.Web.HttpContext.Current.Server.MapPath(_clsObjSendMailTemplatePro.EmailTemplatePath), templateVars);
              

               
               
               SmtpServer = _clsObjSendMailTemplatePro.SmtpServer.Trim().ToString();
               SmtpPassword=_clsObjSendMailTemplatePro.SmtpPassword.Trim().ToString();
               SmtpPort = _clsObjSendMailTemplatePro.SmtpPort.Trim().ToString();
               str_from_address = _clsObjSendMailTemplatePro.FromAddress.Trim().ToString();
               str_to_address = _clsObjSendMailTemplatePro.ToAddress.ToString();
               str_cc_address = _clsObjSendMailTemplatePro.CCAddress.ToString();
               str_bcc_address = _clsObjSendMailTemplatePro.BCCAddress.ToString();


                MailMessage email_msg = new MailMessage();
                email_msg.From = new MailAddress(str_from_address);
                email_msg.Sender = new MailAddress(str_from_address);
                email_msg.ReplyTo = new MailAddress(str_from_address);

                if (str_to_address != "")
                {
                    email_msg.To.Add(str_to_address.Replace(";", ","));
                }

                if (str_cc_address != "")
                {
                    email_msg.CC.Add(str_cc_address.Replace(";", ","));
                }

                if (str_bcc_address != "")
                {
                    email_msg.Bcc.Add(str_bcc_address.Replace(";", ","));
                }

                email_msg.IsBodyHtml = true;
                email_msg.BodyEncoding = System.Text.Encoding.UTF8;
                string s = parser.Parse();
                email_msg.Body = s;
                email_msg.Subject = _clsObjSendMailTemplatePro.Subject.ToString();

             


                SmtpClient mail_client = new SmtpClient();

              
                NetworkCredential network_cdr = new NetworkCredential();
                network_cdr.UserName = str_from_address;
               
                network_cdr.Password = SmtpPassword;
                mail_client.Credentials = network_cdr;
        

               
                mail_client.Port =Convert.ToInt32(SmtpPort);
                
                mail_client.Host = SmtpServer;
               
               
                mail_client.EnableSsl = true;    //Now Send the message    
               
                mail_client.Send(email_msg);


   
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
            }
        }

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

do you have the permission in Go Daddy?  You can modify the config file but the host site also needs the permission.
Random Solutions  
 
programming4us programming4us