我的代码: try
{
MailMessage msg = new MailMessage();
MailAddress address = new MailAddress("发送的邮箱");
MailAddressCollection collection = new MailAddressCollection();
collection.Add("接收的邮箱");
msg.From = address;
msg.To.Add(collection[0].Address.ToString());
msg.IsBodyHtml = true;
msg.Body = "这是我的测试邮件";
string hostName = Dns.GetHostName();
IPAddress[] ipAddress = Dns.GetHostAddresses(hostName);
string ip = ipAddress[0].ToString();
SmtpClient client = new SmtpClient();
client.Host = "qq.smtp.com";
client.Send(msg);
}
catch (Exception ex)
{
Response.Write("<script language='javascript'>alert('" + ex.Message + "')</script>");
}
但是,始终提示发送失败。在这里,我只是写了代码,没有在WEB.CONFIG里面进行配置,也没有设置SMTP服务,请问,代码有问题吗?请给出正确的提示,谢谢!