由于某些原因,我正在接收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