Simple Mail send Through .NET


Hello all ,
Today i will describe how to send mail through .NET
First we have to configure the SMTP mail server . In this context i have assumed you mail server has been configured (including web.config ).
Now we have to import

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

And through the following code we will able to send mail with attachment.

MailMessage msg = new MailMessage();
msg.From = new MailAddress("mail@test.com");
msg.To.Add(new MailAddress("mail_1@test.com"));
msg.To.Add(new MailAddress("mail_2@test.com"));
msg.CC.Add(new MailAddress("mail_3@test.com"));
msg.Bcc.Add(new MailAddress("mail_4@test.com"));
msg.Attachments.Add(new Attachment(@"c:\file.txt"));
msg.Subject = "This is a test mail";
msg.Body = "This is the body of the mail";
SmtpClient client = new SmtpClient();
client.Send(msg);


Leave a Reply