========================================================================
using System.Net.Mail;
public static void SendMail(string From, string To, string Body, string Subject)
{
SmtpClient objSmtpClient = new SmtpClient();
// Given SMTP Server name here.
objSmtpClient.Host = ConfigurationManager.AppSettings["SmtpServer"].ToString();
objSmtpClient.Port = 25;
MailMessage objMailMessage = new MailMessage();
MailAddress objMailAddress = new MailAddress(From);
objMailMessage.From = objMailAddress;
objMailMessage.To.Add(To);
objMailMessage.Subject = Subject;
objMailMessage.IsBodyHtml = true;
objMailMessage.Body = Body;
objMailMessage.Priority = MailPriority.High;
objSmtpClient.Send(objMailMessage);
}
2. Send Mail in Asp.Net with credentials (Host, Username or password)
============================================================
using System.Net.Mail;
public static void SendMail(string From, string To, string Body, string Subject)
{
// Here, You can give SMTP Server Host name or IP Address.
SmtpClient objSmtpClient = new SmtpClient("HostNameOrIP");
MailMessage objMailMessage = new MailMessage();
MailAddress objMailAddress = new MailAddress(From);
objMailMessage.From = objMailAddress;
objMailMessage.To.Add(To);
objMailMessage.Subject = Subject;
objMailMessage.IsBodyHtml = true;
objMailMessage.Body = Body;
objMailMessage.Priority = MailPriority.High;
// Give your SMTP Server UserName and Password
objSmtpClient.Credentials = new System.Net.NetworkCredential("UserName", "Password");
objSmtpClient.Send(objMailMessage);
}
0 comments:
Post a Comment