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
Ananth GPosted Oct 21, 2016, 5:43 AM
Chandranath ShettyPosted Aug 22, 2015, 8:35 AM
Please always post only relevent part of the code.
Vaikesh K PPosted Aug 21, 2015, 6:35 AM
Sample 3 : http://www.codeproject.com/SMTP-E-Mail-Sender-in-Csharp-Console
Vaikesh K PPosted Aug 19, 2015, 5:28 AM
Try this bit of code.
Rajeesh MenothPosted Aug 7, 2015, 4:10 AM
Upendra Pratap ShahiPosted Aug 7, 2015, 2:15 AM
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);
}
}
}
}
}
Upendra Pratap ShahiPosted Aug 7, 2015, 2:05 AM
umair mohsinPosted Aug 7, 2015, 1:25 AM
Rajeesh MenothPosted Aug 6, 2015, 5:59 AM
Upendra Pratap ShahiPosted Aug 6, 2015, 5:50 AM
Rajeesh MenothPosted Aug 6, 2015, 5:42 AM
{
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 ";
}
}
umair mohsinPosted Aug 6, 2015, 5:30 AM
Rajeesh MenothPosted Aug 6, 2015, 3:03 AM
Upendra Pratap ShahiPosted Aug 6, 2015, 2:59 AM
umair mohsinPosted Aug 6, 2015, 2:49 AM
umair mohsinPosted Aug 6, 2015, 2:44 AM
Rajeesh MenothPosted Aug 3, 2015, 2:47 AM
umair mohsinPosted Aug 3, 2015, 2:33 AM
Rajeesh MenothPosted Aug 2, 2015, 5:27 AM
umair mohsinPosted Aug 2, 2015, 2:40 AM
Vignesh ManiPosted Aug 1, 2015, 8:04 AM
Ankit ShuklaPosted Aug 1, 2015, 7:29 AM
Rajeesh MenothPosted Aug 1, 2015, 7:27 AM
{
throw ex ;
}
Vipan SharmaPosted Aug 1, 2015, 6:24 AM
umair mohsinPosted Aug 1, 2015, 6:03 AM
umair mohsinPosted Aug 1, 2015, 6:00 AM
Vipan SharmaPosted Aug 1, 2015, 5:44 AM
Manoj BhoirPosted Aug 1, 2015, 5:36 AM
Vipan SharmaPosted Aug 1, 2015, 5:30 AM