出于某种原因,我收到 Smtp 在当前上下文中不存在,我使用名称空间“使用 System.Net.Mail;”。我不知道为什么并尝试使用 System.Web.mail;。希望你能帮忙。
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);