2010-08-18 131 views
1

我使用的是system.net.mail,並有一個文本框,用戶可以輸入他們的電子郵件地址,並將文件附加併發送給他們。當我在自定義文件夾與服務器2008年,我得到以下錯誤測試:SMTP權限錯誤

請求類型System.Net.Mail.SmtpPermission的」許可....在System.Security.CodeAccessSecurityEngine.Check

我是否必須在服務器上專門配置一些允許的內容?或者它是一個代碼錯誤?

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); 
+0

如果您接受某些問題(並非全部)的答案,您可能會發現您會從社區獲得更多答案。 – 2010-08-18 17:12:13

回答

0

這看起來像是在嘗試從蒸汽中訪問附件時可能會遇到許可問題。如果您明確聲明憑據會發生什麼?

+0

通過在IIS UI上指定憑據和服務器來解決它。但我仍然想知道它是否可以通過編程來指定。 – 2010-08-18 19:27:00