2012-10-21 31 views
0

我試圖發送簡單的郵件在asp.net.it不起作用。ASP.NET簡單郵件發送使用C#

這裏是代碼:

當我運行它產生
protected void Button2_Click(object sender, EventArgs e) 
{ 
    MailMessage mail = new MailMessage(); 
    SmtpClient SmtpServer = new SmtpClient("smtp.gorenparmak.com"); 
    mail.From = new MailAddress("[email protected]"); 
    mail.To.Add("[email protected]"); 
    mail.Subject = "Test Mail - 1"; 
    mail.Body = "mail with attachment"; 

    SmtpServer.Port = 587; 
    SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "write password"); 
    SmtpServer.EnableSsl = true; 

    SmtpServer.Send(mail); 
} 

錯誤:

遠程名稱無法解析:smtp.gorenparmak.com'

如何我能解決這個問題嗎?

+0

這似乎是DNS的問題。首先,這個域是通過主機購買或配置的(例如)? – Rolice

+0

您是否嘗試過使用IP地址而不是DNS名稱? – Kane

+0

嘗試ping smtp.gorenparmak.com並查看是否可以連接遠程服務器。 –

回答

0

嘗試使用25端口爲587端口是用於Gmail的

例嘗試以下,看看它是否工作,否則你有問題與DNS

// Set the to and from addresses. 
// The from address must be your GMail account 
mail.From = new MailAddress("gorenparmak.net<[email protected]>"); 
mail.To.Add(new MailAddress(to)); 

// Define the message 
mail.Subject = subject; 
mail.IsBodyHtml = isHtml; 
mail.Body = message; 

// Create a new Smpt Client using Google's servers 
var mailclient = new SmtpClient(); 
//mailclient.Host = "smtp.gmail.com";//ForGmail 
mailclient.Host = "mail.gorenparmak.com"; 
//mailclient.Port = 587; //ForGmail 
mailclient.Port = 25; 

// This is the critical part, you must enable SSL 
//mailclient.EnableSsl = true;//ForGmail 
mailclient.EnableSsl = false; 
mailclient.UseDefaultCredentials = true; 

// Specify your authentication details 
//mailclient.Credentials = new System.Net.NetworkCredential("[email protected]", "PaswordXYX123");//ForGmail 
mailclient.Credentials = new System.Net.NetworkCredential("[email protected]", "PaSsWaRd"); 

mailclient.Send(mail); 
mailclient.Dispose();