由於某些原因,我正在接收Smtp在當前上下文中不存在,即時使用名稱空間'using System.Net.Mail;'。我不知道爲什麼,並嘗試使用System.Web.mail ;.希望你能幫助。當前上下文中不存在Smtp的名稱
MailMessage mail = new MailMessage();
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Credentials = new System.Net.NetworkCredential("username", "password");
mail.From = ""; //Error 1 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
mail.To = ""; // Error 2 Property or indexer 'System.Net.Mail.MailMessage.To' cannot be assigned to -- it is read only
// Error 3 Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddressCollection'
mail.Subject = "password";
mail.Body = "test";
SmtpMail.SmtpServer = "smtp.brad.ac.uk"; // Error 4 'System.Net.Mail.SmtpClient' does not contain a definition for 'SmtpServer' and no extension method 'SmtpServer' accepting a first argument of type 'System.Net.Mail.SmtpClient' could be found (are you missing a using directive or an assembly reference?)
SmtpMail.Send(mail);
請指出編譯器停止的位置? – 2011-03-17 13:58:02
我在該片段中看不到任何裸露的標識符「Smtp」...複製時是否錯過了某些內容? – 2011-03-17 13:58:06
你在哪裏實例化SmtpClient()? – curtisk 2011-03-17 13:58:38