Emails in C#

This code will help us to send emails.
we use two namespaces for that.
System.Net.Mail and System.Net

On button click:
we first pass the reciver mail address to a string, after this we create new mail message in which the address of sender and the mail address of reciver passed.we can add cc copy to by using MailAddress copy variable.
then just add the copy and subject and revelant informations and server name and send it.

using System.Net.Mail;
using System.Net;

on button click()
string toaddress = ""; //write reciver mail address there
MailMessage mm = new MailMessage(TextBox2.Text, toaddress);
MailAddress copy = new MailAddress(""); //write reciver mail address there
mm.Subject = "some message: " + TextBox3.Text;
mm.Body = "Name:" + TextBox1.Text + "\r\n" + TextBox4.Text;
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient("server name");
Label1.Text = "Thanks";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: