我製作了一個測試頁面,其中包含一個電子郵件地址文本框,一個提交按鈕和一個錯誤標籤。無法通過ASP.NET發送電子郵件給客戶端
下面是C#代碼,我在這裏看到的論壇:
try
{
MailMessage mail = new MailMessage("[email protected]", (string)txtEmail.Text);
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
lblError.Text = "Message sent!";
}
catch (Exception ex)
{
lblError.Text = ex.ToString();
}
完整的錯誤它告訴我的是:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: 'smtp.google.com' at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at email.btnSend_Click(Object sender, EventArgs e) in d:\WebDev\Test\email.aspx.cs:line 28
但它不是爲我工作,我don`不知道該怎麼幫助我!
什麼是「它不是不工作「是什麼意思?它是否給出錯誤信息? –
你會得到什麼錯誤?您將不得不告訴我們「它不適合我」 – user1666620
對不起,我已將完整的錯誤添加到問題主體 – D4NieLDev