Sending email using ASP.NET (C#)

To send email via ASP.NET (C#), please refer to following sample code.

Note: Our mail servers require your script to pass SMTP authentication in order to send email through script.

Sample Code:

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(EMAIL_FROM, EMAIL_TO);
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(STMP_SERVER, SMTP_PORT_NUMBER);

message.IsBodyHtml = true;
message.Subject = YOUR_SUBJECT;
message.Body = YOUR_MESSAGE_BODY;

System.Net.NetworkCredential networkCredential = new System.Net.NetworkCredential();
networkCredential.UserName = EMAIL_FROM;
networkCredential.Password = PASSWORD;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = networkCredential;

try {
smtpClient.Send(message);
}
catch (Exception exp) {
}

  • 359 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

Sending email using ASP.NET (VB.NET)

To send email via ASP.NET (VB.NET), please refer to following sample code.Note: Our mail servers...