public static void MailGonder(string from, string to, string bcc, string cc, string subject, string body)

{

     System.Net.Mail.
MailMessage mMailMessage = new System.Net.Mail.MailMessage();

mMailMessage.From = new System.Net.Mail.MailAddress(from);mMailMessage.To.Add(

new System.Net.Mail.MailAddress(to));

 

if ((bcc != null) && (bcc != string.Empty))

{

mMailMessage.Bcc.Add(
new System.Net.Mail.MailAddress(bcc));

}

 

if ((cc != null) && (cc != string.Empty))

{

mMailMessage.CC.Add(
new System.Net.Mail.MailAddress(cc));

}

mMailMessage.Subject = subject;

 

mMailMessage.Body = body;

 

mMailMessage.IsBodyHtml =
true;mMailMessage.Priority = System.Net.Mail.MailPriority.Normal;

 

System.Net.Mail.
SmtpClient mSmtpClient = new System.Net.Mail.SmtpClient();

 

mSmtpClient.Send(mMailMessage);

}

 

Web.Config dosyasınada şu satırları eklemeniz ve kendi sunucunuza göre ayarlamanız gerekir.

<?xml version="1.0"?>
<
configuration>
   
<
system.net>
      
<
mailSettings>
         
<
smtp from="defaultEmail@yourdomain.com">
            
<
network host="smtp.yourdomain.com" port="25" userName="yourUserName" password="yourPassword"/>
         
</
smtp>
      
</
mailSettings>
   
</
system.net>
</
configuration>

örnek kullanım:

MailGonder("gonderen@yourdomain.com", "alici@yourdomain.com", "bccAddress@yourdomain.com", "ccAddress@yourdomain.com", "Konu", "deneme metni")

Kafanıza takılan soruları sorabilirsiniz

Mustafa KOÇER

mkocer@dotnetkosesi.com

2 kişi tarafından 5.0 olarak değerlendirildi

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5