views:

29

answers:

1
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)
 {
 }
}

and WEB.CONFIG

<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>

i am on my web site's contact, and i fill some textbox and i click send button. later i open [email protected] account but i didnt receive contact information mail.. Where do I make a mistake??

+1  A: 

Try to send a simple email using this snippet:

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

Assuming, [email protected] and yourpassword are your username and password on google.

The differences from your code are the port 587 (instead of your 1772) and use of SSL (EnableSsl = true).

Alex
thanx alex but i cant do it, Can you write clearly according to my Button2_Click
ilkdrl
@ilkdrl, replace your `try...catch` block with a snippet I provided. If it works, the only thing to do is to change port and enable SSL. If it doesn't it would be good you to post some additional info (error or so).
Alex
thaks alex but again i cant do it..i have a mistake in line smtpClient.Send("[email protected]", "[email protected]", "subject", "body");
ilkdrl
@ilkdrl, could you post a whole error?
Alex
yess, its done alex thank you very much..
ilkdrl