How to send a mail… using c# .net!

using System.Net.Mail;

System.Net.Mail.MailMessage oMailMessage = new System.Net.Mail.MailMessage();//creating a mail message object

MailAddress oMailFromAddress = new MailAddress(“kasi@wbcsoftwarelab.com”);//Mail (from-address)

MailAddress oMailToAddress = new MailAddress(“mohan_kings@yahoo.co.in”);//mail address (to-address)

SmtpClient oSmtpClient = new SmtpClient();//object for smtp client.

oSmtpClient.UseDefaultCredentials = true;

oSmtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;//Delivery method.

oSmtpClient.Host = “http://mail.wbcsoftwarelab.com”;//host address.

oMailMessage.From = oMailFromAddress;//giving from address

oMailMessage.To.Insert(0,oMailToAddress);//giving to address

for (int nCount = 0; nCount < a_strToAddress.Count; nCount++)
{

MailAddress oMailCCAddress = new MailAddress(Convert.ToString(a_strToAddress[nCount]));
oMailMessage.CC.Insert(nCount, oMailCCAddress);

}//attaching the cc address from array list.

System.Net.Mail.Attachment oMailAttachment = new System.Net.Mail.Attachment(“c:\\rr.xls”);//Attaching file here.

oMailMessage.Body=””;//Mail content here.

oMailMessage.Attachments.Add(oMailAttachment);//adding attachment

oSmtpClient.Send(oMailMessage);//Message will be send here.

 

admin

Back to top