Bazen yardım ihtiyacı duyabilirsiniz diyerek buraya hatırlatma şeklinde .net 2.0 da mail gönderimi kodumu paylaşmayı düşündüm.
Åžimdi düşünelim ki elimizde 4 TextBox’ımız olsun, bunlar; txt_konu, txt_gond_mail, txt_gonderen, txt_mesaj isimlerine sahip olsunlar. Basit bir ÅŸekilde bir ÅŸirketin mailine otomatik mesaj gönderen kod bu. Ha çalışmaz ise ne yapacaksınız. Burada;
Åžimdi düşünelim ki elimizde 4 TextBox’ımız olsun, bunlar; txt_konu, txt_gond_mail, txt_gonderen, txt_mesaj isimlerine sahip olsunlar. Basit bir ÅŸekilde bir ÅŸirketin mailine otomatik mesaj gönderen kod bu. Ha çalışmaz ise ne yapacaksınız. Burada;
C# |copy code |?
| 1 | System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("mail.sitesite.com", 26); |
Aynı şekilde mail.sitesite.com olan adres ise sizim smtp mail gönderme adresinizdir yine server tarafından verilir.
C# |copy code |?
| 01 | protected void Button1_Click(object sender, EventArgs e) |
| 02 | { |
| 03 | Â Â Â System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); |
| 04 | Â Â Â message.To.Add("info@sitesite.com"); |
| 05 | Â Â Â message.Subject = txt_konu.Text; |
| 06 | Â Â Â message.From = new System.Net.Mail.MailAddress(txt_gond_mail.Text); |
| 07 |    message.Body = "Gönderen : " + txt_gonderen.Text + "\n\n" + "Mesaj: \n " + txt_mesaj.Text + "\n\n\nBu Mail sitesite.com Adresinden Gönderilmiştir!"; |
| 08 | Â Â Â System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("mail.sitesite.com", 26); |
| 09 | |
| 10 | Â Â Â smtp.Send(message); |
| 11 | } |
Bu adreste .net 2.0 ile ilgili tüm mail gönderme standartlarını bulabilirsiniz. Eğer ki ilginizi çeken bir konu bulamazsanız bana da sorabilirsiniz. Bu adresten her türlü ulaşma yolunu listeledim :D
Hepinize iyi .net’li günler dilerim…


