See

Friday, November 16, 2007

Sending mail Thorough c#.Net

Sending mail Thorough c#.Net

For it to work U have to have a smtp server and credential for that server.
If u have gamilid u can also use it.

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Net.Mime;
using System.Configuration;
namespace mail
{
class Program
{
static void Main(string[] args)
{

MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@gmail.com", "Hi..........");
msg.To.Add(“aa@abc.com”);
msg.Subject = "Sending Mail Through C#";
msg.Body = " This is first mail through C#.net For this u have to gmail id .there are many other server which u can use but gmail is better one. Or u have ur own Smtp seever. ";
SmtpClient client = new SmtpClient();
client.Credentials =
new System.Net.NetworkCredential("abc@gmail.com", "password");
// u must provide login id and password.
client.Port = 587;//or use 587

msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;



client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Send(msg);
}
}

No comments: