Using this code (System.Net.Mail):
SmtpClient client = new SmtpClient();
client.Send(MyMessage);
I get this error:
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25
Web.config entries.
Working code.
{
string body = "";
body = "<table border='0' align='center' cellpadding='2' style='border-collapse: collapse' bordercolor=''#111111' width='100%' id='AutoNumber1'>";
body = body + "<tr><td width='100%' align='center' colspan='6'><b>Feed Back Form</b></td></tr>";
body = body + "<tr><td width='100%' colspan='6'> </td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Name</td><td width='50%' colspan='4'><b>" + name.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Address</td><td width='50%' colspan='4'><b>" + Address.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>City</td><td width='50%' colspan='4'><b>" + City.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>State</td><td width='50%' colspan='4'><b>" + State.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Country</td><td width='50%' colspan='4'><b>" + Country.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Zip/Pin Code</td><td width='50%' colspan='4'><b>" + ZipCode.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Phone</td><td width='50%' colspan='4'><b>" + Phone.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>E-Mail</td><td width='50%' colspan='4'><b>" + email.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Website URL (If Any)</td><td width='50%' colspan='4'><b>" + weburl.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>How did you know about Country Oven?</td>";
body = body + "<td width='50%'><b>" + radiobutn.SelectedItem.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Your feedback/suggestions for the site</td>";
body = body + "<td width='50%' colspan='4'><b>" + txtsugg.Text + "</b></td></tr>";
body = body + "<tr><td width='50%' colspan='2'>Query (If you have any)</td>";
body = body + "<td width='50%' colspan='4'><b>" + query.Text + "</b></td></tr></table>";
MailMessage message = new MailMessage();
message.To = "contact@xxxx.com";
message.From = email.Text;
message.Subject = "ContactUs Form";
message.BodyFormat = MailFormat.Html;
message.Body = body;
SmtpMail.SmtpServer.Insert(0, "");
SmtpMail.Send(message);
// lblmsg.Text = "Message sent successfully";
RegisterStartupScript("startupScript", "<script language=JavaScript>alert('Message sent successfully.');</script>");
clear();
}
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network defaultCredentials="True" host="LocalHost" port="25" />
</smtp>
</mailSettings>
</system.net>
What is wrong ?