How To send mail from asp.net C#
especially when dealing with different hosting providers.
Here is working Code
First Create one email id of your domain From your hosting provider
using System.Net.Mail;
public void sendLocalmail(String from, String to, String Cc, String subject , String Mailbody)
{
MailMessage MM = new MailMessage();
MM.Attachments.Add(new Attachment());
MM.Body = Mailbody;
MM.From = new MailAddress(from);
MM.To.Add(to);
MM.CC.Add(Cc);
MM.Subject = subject ;
MM.IsBodyHtml = true;
MM.BodyEncoding = System.Text.Encoding.UTF8;
MM.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(youremail@domain_name.com, "password");
//use your domain email id as username and its password
client.Port = Convert.ToInt32("25");
//if port 25 not work 'use465 or 587 ports
client.Host = "mail.domain_name.com.";
//SMTP Host address of your domain name not required any gmail,hotmail email id check ur dns setting
client.EnableSsl = true;
//on some server ssl my not suport then try to client.EnableSsl = false;
client.Send(MM);
}
//its working code like php contact form always work
No comments:
Post a Comment