Send mail using ASP.NET
This code shows how to send Email from ASP.NET using your Gmail account
send Email from ASP.NET using your Gmail account
Fist you prepair the application mail.aspx.
like this:
< body>
< form id="form1" runat="server">
< div>
< div style="width: 408px; height: 242px">
< strong> To:</strong>< asp:TextBox ID="ToText" runat="server" Width="263px"></asp:TextBox>
<br />
< strong> From:</strong>
< asp:TextBox ID="FromText" runat="server" Width="256px">< /asp:TextBox>
< strong> Subject:</strong>
< asp:TextBox ID="SubjectText" runat="server" Width="244px" >< /asp:TextBox> <br />
< strong> Message:</strong>
< asp:TextBox ID="MessageText" runat="server" Height="106px" Width="310px">< /asp:TextBox> <br />
<br />
< asp:Button ID="Buttsend" runat="server" Text="Send" Width="77px" OnClick="Buttsend_Click" />
<asp:Label ID="Label2" runat="server"> < asp:Button ID="Buttcancel" runat="server" OnClick="Buttcancel_Click" Text="Cancel" >
< /asp:Button>
< asp:Label ID="Label1" runat="server"> < /div>
< /div>
< /form>
< /body>
and mail.aspx.cs
copy this bellow program..
and you must give bellow program your gmail username and password..
i mentioned in comment tags in program...
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Buttsend_Click(object sender, EventArgs e)
{
MailMessage mm = new MailMessage();
SmtpClient smtp = new SmtpClient();
mm.From = new MailAddress(FromText.Text);
mm.To.Add(new MailAddress(ToText.Text));
mm.Subject = SubjectText.Text;
mm.Body = MessageText.Text;
mm.IsBodyHtml = true;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "your gamail.com";//write your gmail user name
NetworkCred.Password = "your password";// write pass word smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587; //Gmail port for e-mail 465 or 587
smtp.Send(mm);
Label2.Text = "succecc fully send";
}
protected void Buttcancel_Click(object sender, EventArgs e)
{
Label1.Text = "try again";
}
}
Reference: http://naveenkumarm.page.tl
Hi,
I had used same code after execution i am getting this error:
No connection could be made because the target machine actively refused it 74.125.53.109:587
can you help me regarding this..
Thanks