SMTP权限错误

时间:2010-08-18 17:02:30

标签: c# asp.net smtp

我正在使用system.net.mail并且有一个文本框,用户可以输入他们的电子邮件地址并附加一个文件并发送给他们。当我在Server 2008的自定义框中测试时,出现以下错误:

在System.Security.CodeAccessSecurityEngine.Check上请求获得类型'System.Net.Mail.SmtpPermission ....的权限

我是否必须在服务器上专门配置一些允许的内容?或者是代码错误?

string strto = txtTo.Text;  

//create the mail message
                MailMessage mail = new MailMessage();

                //set the addresses
                mail.From = new MailAddress("serveremail");
                mail.To.Add(strto);

                //set the content
                mail.Subject = "subject";


                //Get some binary data
                byte[] byteArray = Encoding.ASCII.GetBytes(result);


                //save the data to a memory stream
                using (MemoryStream ms = new MemoryStream(byteArray))

                    //create the attachment from a stream. Be sure to name the data with a file and 
                    //media type that is respective of the data
                    mail.Attachments.Add(new Attachment(ms, "test.txt", "text/plain"));

                //send the message
                SmtpClient smtp = new SmtpClient("server");
                smtp.Send(mail);

1 个答案:

答案 0 :(得分:0)

当尝试从Steam访问附件时,这似乎是一个权限问题。如果明确说明凭证会发生什么?