我正在尝试以编程方式发送电子邮件,但我一直收到以下错误:
无法解析远程名称:'smtp.gmail.com'
这是我正在尝试的代码:
string sender = "example@gmail.com";
string password = "myPwd";
string host = "smtp.gmail.com";
int port = "587";
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient();
smtpServer.Host = host;
mail.From = new MailAddress(sender);
mail.To.Add(recipient);
mail.Subject = emailSubject;
mail.Body = body;
mail.IsBodyHtml = true;
smtpServer.Port = port;
smtpServer.Credentials = new NetworkCredential(sender, password);
smtpServer.EnableSsl = true;
smtpServer.Send(mail);
我一直在努力,但我不明白出了什么问题。有人可以帮忙吗?