Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
When I'm trying to send an email in my code it gives me an error that says

object refrence not set to an instance of an object

Can you please help? I don't know what to do now.


-- Added --
VB
'send email
Try
      Dim objemail As New _email()
      objemail.from = System.Configuration.ConfigurationManager.AppSettings("UserName").ToString()
      objemail.[to] = Convert.ToString(txt_email.Text)
      objemail.subject = txtSubjects.Text
      objemail.body = txt_Message.Text
      objemail.IsHTML = False
      objemail.SendMail()
      lblSucc_Email.Text = "Email sent"
Catch er As Exception
      lbl_error_Email.Text = er.Message
End Try
Posted
Updated 29-Aug-11 10:03am
v2
Comments
AspDotNetDev 29-Aug-11 14:54pm    
Update your question with the code you are using. There are TONS of possibilities.
AspDotNetDev 29-Aug-11 17:40pm    
What line does the error appear on? In what method did you put the code in (e.g., page load, form load, button click)?
simtho 30-Aug-11 5:30am    
it doesnt show the line. the code is under the button
TheyCallMeMrJames 30-Aug-11 10:17am    
What line number is the error on? Have you attached a debugger?
simtho 30-Aug-11 12:56pm    
It doesnt show the line. It says that message 4rom
Catch er As Exception
lbl_error_Email.Text = er.Message
End Try.

There is an object that you did not initialize before you tried to use it.

Without seeing your code that corresponds to the error line number, we won't be able to help more than that.

Chances are you've got some copy-and-pasted code that you didn't fully copy, you're missing the = new SomeObject().

Cheers.
 
Share this answer
 
Comments
simtho 30-Aug-11 5:31am    
i have pasted the code in Solution 3 please help
You're doing it wrong.

I know, my answer might seem vague, or even obtuse, but the quality of the question dictates the quality of the ansewr.
 
Share this answer
 
Comments
simtho 30-Aug-11 5:30am    
i have pasted the code i solution 3 please help

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