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
Gomathi PalaniswamyPosted Oct 25, 2010, 6:33 AM
see the link
http://www.aspnettutorials.com/tutorials/email/email-aspnet2-csharp.aspx
Suthish NairPosted Oct 25, 2010, 6:21 AM
Koteswararao MallisettiPosted Oct 25, 2010, 5:57 AM
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
Dhaivat ShahPosted Oct 25, 2010, 5:54 AM
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.