How to Send Email In Asp.net 2.0 ?
I use following code but it is not work ......
string UserFNameCase = txtname.Text;
string dsCenter = ddlDistribution.SelectedItem.Text;
string MailSub = "Registration Information.";
string EventDescription = " Dear " + UserFNameCase + ",
Your Serial No is " + SerialNo + " . Please collect your Id card From " + dsCenter + " after 2 bussiness days .";
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.Subject = "Registration Information.";
mail.Body = EventDescription;
mail.From = new MailAddress("[email protected]");
mail.To.Add(txtEmail.Text);
SmtpClient smtp = new SmtpClient("localhost");
//smtp.Host = "127.0.0.1";
smtp.Host = "LocalHost";
smtp.Credentials = new NetworkCredential("username", "secret");
////smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
smtp.Send(mail);
Loading

Dhaivat Shah10 reputationPosted Oct 25, 2010, 1:54 AM EDT
using System.Net.Mail;
then try below code for sending Mail
string UserFNameCase = txtname.Text;
string dsCenter = ddlDistribution.SelectedItem.Text;
string MailSub = "Registration Information.";
string EventDescription = " Dear " + UserFNameCase + ",
Your Serial No is " + SerialNo + " . Please collect your Id card From " + dsCenter + " after 2 bussiness days .";
MailMessage mMailMessage = new MailMessage();
SmtpClient mSmtpClient = new SmtpClient();
MailMessage.From = new MailAddress("[email protected]");
MailMessage.To.Add(new MailAddress(txtEmail.Text));
MailMessage.Subject = "Registration Information.";
MailMessage.Body = EventDescription;
MailMessage.IsBodyHtml = true;
mSmtpClient.Host = "LocalHost";
mSmtpClient.UseDefaultCredentials = true;
mSmtpClient.Port = 25;
mSmtpClient.EnableSsl = false;
mSmtpClient.Send(mMailMessage);
if above code work then Mark as Answer.
Koteswararao MallisettiRank #2,740 · 511 reputationPosted Oct 25, 2010, 1:57 AM EDT
smtpObj.Host = HostName; //here you give the "gmail.com" like this
smtpObj.Credentials = new NetworkCredential(_userName.Trim(), _password.Trim());
smtpObj.Port = _portNo; //you must specify the port no on which the smtp server was running
remaining all are correct this code is work for me specify the port no of smtp server may be it the problem
Suthish NairRank #92 · 22.8K reputationPosted Oct 25, 2010, 2:21 AM EDT
Gomathi PalaniswamyRank #714 · 3.3K reputationPosted Oct 25, 2010, 2:33 AM EDT
see the link
http://www.aspnettutorials.com/tutorials/email/email-aspnet2-csharp.aspx