Mail g繹nderebilmek i癟in, projemizin namespace’lerine using System.Net.Mail; namespace’ni eklememiz gerekmektedir.
C# Kod rnei
public void MailGonder(
string GonderenAdSoyad,
string GonderenEmail,
string AliciEmail,
string AliciAdSoyad,
string konu,
bool HtmlFormat,
string MailIcerigi,
string SmtpSunucu,
string GonderimiYapacakEmail,
string GonderimiYapacakEmailSifresi)
{
System.Net.Mail.MailAddress gonderen = new System.Net.Mail.MailAddress
(GonderenEmail, GonderenAdSoyad);
System.Net.Mail.MailAddress alan = new System.Net.Mail.MailAddress
(AliciEmail, AliciAdSoyad);
System.Net.Mail.MailMessage eposta = new System.Net.Mail.MailMessage
(gonderen, alan);
eposta.IsBodyHtml = HtmlFormat;
eposta.Subject = konu;
eposta.Body = MailIcerigi;
System.Net.NetworkCredential auth = new System.Net.NetworkCredential
(GonderimiYapacakEmail, GonderimiYapacakEmailSifresi);
System.Net.Mail.SmtpClient SMTP = new System.Net.Mail.SmtpClient();
SMTP.Host = SmtpSunucu;
SMTP.UseDefaultCredentials = false;
SMTP.Credentials = auth;
SMTP.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
try
{
SMTP.Send(eposta);
Response.Write(“Mail G繹nderildi !”);
}
catch (Exception ex)
{
Response.Write(“Mail G繹nderilemedi, Sebebi: ” + ex.Message);
}
}
Vb.Net Kod rnei
Public Sub MailGonder(ByVal GonderenAdSoyad As String, ByVal GonderenEmail As String, ByVal AliciEmail As String, ByVal AliciAdSoyad As String, ByVal konu As String, ByVal HtmlFormat As Boolean, _
ByVal MailIcerigi As String, ByVal SmtpSunucu As String, ByVal GonderimiYapacakEmail As String, ByVal GonderimiYapacakEmailSifresi As String)
Dim gonderen As New System.Net.Mail.MailAddress(GonderenEmail, GonderenAdSoyad)
Dim alan As New System.Net.Mail.MailAddress(AliciEmail, AliciAdSoyad)
Dim eposta As New System.Net.Mail.MailMessage(gonderen, alan)
eposta.IsBodyHtml = True
eposta.Subject = konu
eposta.Body = MailIcerigi
Dim auth As New System.Net.NetworkCredential(GonderimiYapacakEmail, GonderimiYapacakEmailSifresi)
Dim SMTP As New System.Net.Mail.SmtpClient()
SMTP.Host = SmtpSunucu
SMTP.UseDefaultCredentials = False
SMTP.Credentials = auth
SMTP.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Try
SMTP.Send(eposta)
Response.Write(“Mail G繹nderildi !”)
Catch ex As Exception
Response.Write(“Mail G繹nderilemedi, Sebebi: ” + ex.Message)
End Try
End Sub