.Request类型'System.Net.Mail.SmtpPermission,System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'的权限失败

时间:2015-08-18 19:22:23

标签: c# asp.net smtp

Godaddy说我们无法获得有关此事的信息

try
                {
                    //Create the msg object to be sent
                    MailMessage msg = new MailMessage();
                    //Add your email address to the recipients
                    msg.To.Add("ramuglp@gmail.com");
                    //Configure the address we are sending the mail from
                    MailAddress address = new MailAddress("ramuglp@gmail.com ");
                    msg.From = address;
                    msg.Subject = "TEST";
                    msg.Body = "TEST BODY";

                    //Configure an SmtpClient to send the mail.            
                    SmtpClient client = new SmtpClient();
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.EnableSsl = true; 
                    client.Host = "smtp.gmail.com"; 
                    client.Port = 25;  

                //Setup credentials to login to our sender email address ("UserName", "Password")
                    NetworkCredential credentials = new NetworkCredential("ramuglp@gmail.com", "**********");
                client.UseDefaultCredentials = true;
                    client.Credentials = credentials;

                    //Send the msg
                    client.Send(msg);

                    //Display some feedback to the user to let them know it was sent
                    confirmationLabel.Text+ = "Your message was sent!";
                }
                catch (Exception ex)
                {
                    //If the message failed at some point, let the user know
                    confirmationLabel.Text = "Your message was NOT sent!"+ex.ToString();
                //"Your message failed to send, please try again."
                }

0 个答案:

没有答案