using System; using System.Web; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net.Mail; using System.IO; using System.Web.UI; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MailMessage objEmail = new MailMessage(); objEmail.To = convert.System.Net.Mail.MailAddressCollection(txtTo.Text); objEmail.From = convert.System.Net.Mail.MailAddressCollection(txtFrom.Text); objEmail.Subject = "Test Email"; objEmail.Body = txtName.Text + ", " + txtComments.Text; objEmail.Priority = MailPriority.High; SmtpMail.SmtpServer = "smtp.sbcglobal.yahoo.com"; try { SmtpMail.Send(objEmail); Response.Write("Your Email has been sent sucessfully - Thank You"); } catch (Exception exc) { Response.Write("Send failure: " + exc.ToString()); } } } }
<big>MY new code i m giving as belove</big> using System; using System.Web; using System.Drawing; using System.Text; using System.Web.UI; using System.Windows.Forms; using System.Net.Mail; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { MailMessage objEmail = new MailMessage(); objEmail.To = txtTo.Text; objEmail.Subject = "Test Email"; objEmail.From = txtFrom.Text; objEmail.Body = txtName.Text + ", " + txtComments.Text; SmtpClient send = new SmtpClient("smtp.sbcglobal.yahoo.com"); objEmail.Priority = MailPriority.High; try { send.Send(objEmail); label4.Text = "Your Email has been sent sucessfully - Thank You"; } catch (Exception exc) { label4.Text = "Send failure: " + exc.ToString(); } } } now error is <big> <pre lang="vb">Error 1 Property or indexer System.Net.Mail.MailMessage.To' cannot be assigned to -- it is read only
Response.Write("Send failure: " + exc.ToString())
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)