i am having a n issue is sending a mail message using asp,net web application.
i have applied all the things which i could do but there is an error always occur.
here is my code.can anyone please guide me
UI
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DemoContact Us Form.aspx.cs" Inherits="DemoContact_Us_Form" %>
code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class DemoContact_Us_Form : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label5.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
{
MailMessage mm = new MailMessage();
mm.From = new MailAddress(txtmail.Text);
mm.To.Add("[email protected]");
mm.Subject = txtsubject.Text;
mm.Body = txtcommnets.Text;
mm.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.live.com";
client.Credentials = new System.Net.NetworkCredential("","");
client.UseDefaultCredentials = true;
client.Port = 25;
client.EnableSsl = true;
client.Send(mm);
Label5.ForeColor = System.Drawing.Color.BlueViolet;
Label5.Text = " thank you for contacting us your mail has received ";
txtmail.Enabled = false;
txtname.Enabled = false;
txtsubject.Enabled = false;
txtcommnets .Enabled = false;
}
}
catch (Exception ex)
{
Label5.ForeColor = System.Drawing.Color.Red;
Label5.Text = " there is a problem sending your email.please try again later ";
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class DemoContact_Us_Form : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label5.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
{
MailMessage mm = new MailMessage();
mm.From = new MailAddress(txtmail.Text);
mm.To.Add("[email protected]");
mm.Subject = txtsubject.Text;
mm.Body = txtcommnets.Text;
mm.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.live.com";
client.Credentials = new System.Net.NetworkCredential("","");
client.UseDefaultCredentials = true;
client.Port = 25;
client.EnableSsl = true;
client.Send(mm);
Label5.ForeColor = System.Drawing.Color.BlueViolet;
Label5.Text = " thank you for contacting us your mail has received ";
txtmail.Enabled = false;
txtname.Enabled = false;
txtsubject.Enabled = false;
txtcommnets .Enabled = false;
}
}
catch (Exception ex)
{
Label5.ForeColor = System.Drawing.Color.Red;
Label5.Text = " there is a problem sending your email.please try again later ";
}
}
}
i have entered password and username is network credentials.but it still throw an error .please help me in this

Vipan SharmaRank #1,589 · 999 reputationPosted Aug 1, 2015, 1:30 AM EDT
Manoj BhoirRank #599 · 4K reputationPosted Aug 1, 2015, 1:36 AM EDT
Vipan SharmaRank #1,589 · 999 reputationPosted Aug 1, 2015, 1:44 AM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 1, 2015, 2:00 AM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 1, 2015, 2:03 AM EDT
Vipan SharmaRank #1,589 · 999 reputationPosted Aug 1, 2015, 2:24 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 1, 2015, 3:27 AM EDT
{
throw ex ;
}
Ankit ShuklaRank #2,120 · 672 reputationPosted Aug 1, 2015, 3:29 AM EDT
Vignesh ManiRank #98 · 22.1K reputationPosted Aug 1, 2015, 4:04 AM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 1, 2015, 10:40 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 2, 2015, 1:27 AM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 2, 2015, 10:33 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 2, 2015, 10:47 PM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 5, 2015, 10:44 PM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 5, 2015, 10:49 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 5, 2015, 10:59 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 5, 2015, 11:03 PM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 6, 2015, 1:30 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 6, 2015, 1:42 AM EDT
{
try
{
if (Page.IsValid)
{
MailMessage mm = new MailMessage();
mm.From = new MailAddress(txtmail.Text);
mm.To.Add("[email protected]");
mm.Subject = txtsubject.Text;
mm.Body = txtcommnets.Text;
mm.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "smtp.live.com";
client.Credentials = new System.Net.NetworkCredential("youremail id","email id password");
client.UseDefaultCredentials = false;
client.Port = 465; // only for hotmail check other port number ref my article
client.EnableSsl = true;
client.Send(mm);
Label5.ForeColor = System.Drawing.Color.BlueViolet;
Label5.Text = " thank you for contacting us your mail has received ";
txtmail.Enabled = false;
txtname.Enabled = false;
txtsubject.Enabled = false;
txtcommnets .Enabled = false;
}
}
catch (Exception ex)
{
//Label5.ForeColor = System.Drawing.Color.Red;
//Label5.Text = " there is a problem sending your email.please try again later ";
}
}
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 6, 2015, 1:50 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 6, 2015, 1:59 AM EDT
umair mohsinRank #3,092 · 463 reputationPosted Aug 6, 2015, 9:25 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 6, 2015, 10:05 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Aug 6, 2015, 10:15 PM EDT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
namespace DBFirstWeb
{
public partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void MailSend()
{
string smtpAddress = "smtp.live.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "[email protected]";
string password = "pwd!@#";
string emailTo = "****@gmail.com";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
}
}
}
}
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 7, 2015, 12:10 AM EDT
Vaikesh K PRank #808 · 2.8K reputationPosted Aug 19, 2015, 1:28 AM EDT
Try this bit of code.
Chandranath Shetty157 reputationPosted Aug 22, 2015, 4:35 AM EDT
Please always post only relevent part of the code.
Ananth GRank #1,176 · 1.5K reputationPosted Oct 21, 2016, 1:43 AM EDT
Vaikesh K PRank #808 · 2.8K reputationPosted Aug 21, 2015, 2:35 AM EDT
Sample 3 : http://www.codeproject.com/SMTP-E-Mail-Sender-in-Csharp-Console