C# How to Send Email

4/1/2014·1 min read

Using C#.NET could easily send email, so the dll is under System.Net.Mail. Here'll show how to simply sending email if your SMTP is setup already.

Ok, i'll stop talking, just sharing code sample.

 	string  emailReceiver = "" ;
 
 			SmtpClient  mailClient = new  SmtpClient ("localhost" );
 			mailClient.UseDefaultCredentials = true ;
 			mailClient.DeliveryMethod = SmtpDeliveryMethod .PickupDirectoryFromIis;
 
 			MailMessage  message = new  MailMessage ();
 			MailAddress  address = new  MailAddress (emailReceiver);
 			message.From = address;
 			message.To.Add(address);
 			message.Subject = "test email" ;
 			message.SubjectEncoding = Encoding .Unicode;
 			message.BodyEncoding = Encoding .Unicode;
 			StringBuilder  sb = new  StringBuilder ();
 			message.Body = "sending email!" ;
 			message.Priority = MailPriority .Normal;
 			mailClient.Send(message);
 
result of email