2010-05-20 41 views
0
protected void Button2_Click(object sender, EventArgs e) 
{ 
string ad = TextBox1.Text; 
string firma = TextBox2.Text; 
string mail = TextBox3.Text; 
string tel = TextBox4.Text; 
string tel2 = TextBox5.Text; 
string fax = TextBox6.Text; 
string fax2 = TextBox7.Text; 
string web = TextBox8.Text; 
string mesaj = TextBox9.Text; 

try 
{ 
    string fromAddress = "[email protected]"; 
    string fromName = "user"; 
    string toMail = "[email protected]"; 
    string toNme = "Mr."; 
    string msgSubject = "Contact"; 
    string sifre = "userpassword"; 

    string msgBody = "you have a message; \n" 
    + "\n" 
    + "\n" 
    + "Mesaj? Gonderenin Ad? :" + ad + "\n" 
    + "Mesaj? Gonderen Firma :" + firma + "\n" 
    + "Mesaj? Gonderenin Maili :" + mail + "\n" 
    + "Mesaj? Gonderenin Tel. Numaras? :" + tel + tel2 + "\n" 
    + "Mesaj? Gonderenin Fax Numaras? :" + fax + fax2 + "\n" 
    + "Mesaj? Gonderenin Web Adresi :" + web + "\n" 
    + "\n" 
    + "\n" 
    + "" + mesaj + "" 
    + "\n" 
    + "\n" 
    + "=======================================" + "\n"; 

    SmtpClient client = new SmtpClient(); 
    client.Credentials = 
    new System.Net.NetworkCredential(fromAddress, sifre); 
    client.Host = "smtp.gmail.com"; 
    client.Port = 1772; 
    client.EnableSsl = false; 
    MailAddress from = new MailAddress(fromAddress, fromName); 
    MailAddress to = new MailAddress(toMail, toNme); 
    MailMessage message = new MailMessage(from, to); 

    message.Subject = msgSubject; 
    message.Body = msgBody; 

    client.Send(message); 
    Response.Redirect("iletisim.aspx"); 
} 
catch (Exception ex) 
{ 
} 
} 

和WEB.CONFIG用c#.net問題發送聯繫人信息中的郵件?幫助請

<configuration> 
    <system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network" from="[email protected]"> 
     <network host="smtp.gmail.com" port="1772" defaultCredentials="false" 
      userName="user" password="userpassword"/> 
     </smtp> 
    </mailSettings> 
    </system.net> 
</configuration> 

我對我的網站上的聯繫,而且我填補一些文本框,我點擊發送按鈕。後來我打開[email protected]帳戶,但我沒有收到聯繫信息郵件..我在哪裏犯了一個錯誤?

+0

你真的明白你在這裏發佈你的登錄/密碼嗎?馬上改變你的密碼!永遠不要顯示它! – Alex 2010-05-20 22:05:19

+0

我希望這不是真正的您的實時用戶名和密碼。另外,發佈你得到的錯誤將有助於確定如何解決你的問題。 – Kelsey 2010-05-20 22:06:44

+0

我在我的網站的聯繫人,我填寫一些文本框,我點擊發送按鈕。後來我打開[email protected]帳戶,但我沒有收到聯繫信息郵件..我在哪裏犯了一個錯誤? – ilkdrl 2010-05-20 22:15:32

回答

1

嘗試使用這個片段發送一個簡單的電子郵件:

var smtpClient = new SmtpClient("smtp.gmail.com", 587) 
    { 
     Credentials = new NetworkCredential(
      "[email protected]", 
      "yourpassword" 
     ), 
     EnableSsl = true 
    }; 
    smtpClient.Send("[email protected]", "[email protected]", "subject", "body"); 

假設,[email protected]yourpassword您對谷歌的用戶名和密碼。 (代替1772)和使用SSLEnableSsl = true)。

+0

thanx亞歷克斯,但我不能這樣做,你能寫清楚根據我的Button2_Click – ilkdrl 2010-05-20 22:45:13

+0

@ilkdrl,用我提供的代碼片段替換你的'try ... catch'塊。如果有效,唯一要做的就是更改端口並啓用SSL。如果它不是,你會發布一些額外的信息(錯誤或其他)。 – Alex 2010-05-20 23:18:29

+0

thaks亞歷克斯,但我不能這樣做.. 我有一個錯誤行 smtpClient.Send(「[email protected]」,「[email protected]」,「主題」,「身體」); – ilkdrl 2010-05-20 23:42:31