Asked by:
How to send mail from asp.net2.0

Question
-
User1070930063 posted
Hi,
How to send email from asp.net2.0.I have written the following code but it is giving some error.please someone help me.
protected void btnclick_Click(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress(txtmail.Text, txtname.Text);
smtpClient.Host = "localhost";
smtpClient.Port = 25;
message.From = fromAddress;
message.To.Add("xyz@gmail.com");
message.Subject = "Feedback";
message.IsBodyHtml = false;
message.Body = txtmsg.Text;
smtpClient.Send(message);
}
catch (Exception ex)
{
}
The error it is giving is "Mailbox unavailable. The server response was: 5.7.1 Unable to relay for xyz@gmail.com"
Thanks.
Monday, August 11, 2008 5:27 AM
All replies
-
User388626632 posted
You should replace 'localhost' and port in
smtpClient.Host = "localhost";
smtpClient.Port = 25;with your real smtp server & port number
Monday, August 11, 2008 6:02 AM -
User1070930063 posted
Hi, Thanks for the reply...can you please elaborate ur explaination a bit..i dint get you.SMTP Server???
i
Monday, August 11, 2008 7:22 AM -
User388626632 posted
Hi, Thanks for the reply...can you please elaborate ur explaination a bit..i dint get you.SMTP Server???
i
For example if you will use Gmail account to send emails
// Smtp configuration SmtpMail.SmtpServer = "smtp.gmail.com";//smtp is :smtp.gmail.com // - smtp.gmail.com use smtp authentication mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "myemail@gmail.com"); mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "mypassword"); // - smtp.gmail.com use port 465 or 587 mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");//port is: 465 // - smtp.gmail.com use STARTTLS (some call this SSL) mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
Monday, August 11, 2008 8:02 AM -
User1070930063 posted
HI, I just want to develop a contacts page as part of my website.Any user can type their name,mailid and message and send it to admin.How to do this...?your reply is greatly appreciated. Thanks.
Tuesday, August 12, 2008 4:17 AM