Code :Aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
//using System.Web.Mail.SmtpMail;
public partial class SendEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_send_Click(object sender, EventArgs e)
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress(txtfrom.Text);
Msg.To.Add(txtto.Text);
Msg.Subject = txtsubject.Text;
Msg.Body = txtbody.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential(txtfrom.Text,txtpassword.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
//using System.Web.Mail.SmtpMail;
public partial class SendEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_send_Click(object sender, EventArgs e)
{
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress(txtfrom.Text);
Msg.To.Add(txtto.Text);
Msg.Subject = txtsubject.Text;
Msg.Body = txtbody.Text;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential(txtfrom.Text,txtpassword.Text);
smtp.EnableSsl = true;
smtp.Send(Msg);
}
That is for gmail account only from gmail to any.
ReplyDelete