Click here to Skip to main content
15,895,792 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m writing this programme for sending an email using another smtp sever
but one error is occured during compilation
so can anybody help me?
i need your help guys
The Error is :
(
The type or namespace name 'UI' does not exist in the namespace 'System.Web'(are you missing an assembly reference?
)

plz solve it.

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 

so tell me how to assign this ....

Posted
Updated 9-Jun-10 19:49pm
v3

In windows application you don't get the reference of System.Web by default. If you still want to use this in that case you can add the reference of the System.Web to you project. Right click on the solution explorer -> Add reference and select System.Web.


I believe you was trying to create a webapplication but you have created windows as I can find Response.Write("Send failure: " + exc.ToString()); statement in your code.
 
Share this answer
 
v2
Comments
dhavalthakor 9-Jun-10 7:18am    
thanx for giving me answer..
i hav corrected your my coding ..
i have put a label in place of response.redirect....
but again same error ....

using System.Web.UI;

error is same:
"The type or namespace name 'UI' does not exist in the namespace 'System.Web'(are you missing an assembly reference?"
PSK_ 9-Jun-10 7:20am    
I told you to add the reference of the System.Web library to you project. Right click on the solution explorer -> Add reference and select System.Web from the list.
Why did you include it, if you don't use it ? Is this just blindly copied from the web ? What happens if you remove the include that you don't reference at all ?
 
Share this answer
 
Comments
Sandeep Mewara 9-Jun-10 0:54am    
That's why a blind copy-paste is dangerous!
dhavalthakor 9-Jun-10 7:17am    
if i m removing this .....
the error comes.
convert not into current context.
smtpmail not into current context.

plz solve my prob...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900