Hi Hasan,
I think u hav not assigned SMTP server to ur MailMessage object. If u r connected with internet then u can use localhost as ur SMTP server & u will surely recieve ur mails. But there are some servers that accept this type of mails bcoz these mails r not authorised, so goes to spam or bulk folders. Also u can't send mails from all emails like yahoo, gmail,aol etc(which does'nt support. gmail support but yahoo not).
Try this code...
try
{
MailMessage objMailMsg = new MailMessage();
objMailMsg.From = txtFrom.Text.Trim();
objMailMsg.To = txtTo.Text.Trim();
objMailMsg.Subject = txtSubject.Text.Trim();
objMailMsg.Body = txtName.Text + " wrote, " + txtComments.Text;
SmtpMail.SmtpServer="localhost";
SmtpMail.Send(objMailMsg);
Response.Write("Your mail has been send successfully");
}
catch(Exception exc)
{
lblMessage.Text = "Send fail: " + exc.ToString();
}
|