• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1643
  • Last Modified:

system.net.mail - Property to is read-only

I am sending an email using vb.net and for some strange reason I am being told that the 'To' property is read  only! Can anyone tell me why this is occurring???

Exception Details: System.MissingMemberException: Property 'To' is ReadOnly.


Imports System.Net
Imports System.Net.Mail

        Dim message = New MailMessage()
        message.To = New MailAddress("simongoldsmith@clearchannel.com")
        message.From = "test@test.com"
        message.Subject = Request.Form("SubjectTextBox")
        message.Body = Request.Form("ContentTextBox")
        Dim smtp = New SmtpClient()
        Try
            smtp.Send(message)
            ErrorMessage.Text = "Your E-mail has been sent - Thank You"
        Catch ex As Exception
            Response.Write("Send failure: " + ex.ToString())
        End Try
0
clearchannel
Asked:
clearchannel
  • 2
1 Solution
 
PaulHewsCommented:
I think you need to use

Message.To.Add(New MailAddress("simongoldsmith@clearchannel.com"))
0
 
PaulHewsCommented:
It's a collection rather than a singular object.
0
 
TSmoothCommented:
You can set the To address(es) in the constructor of MailMessage()

e.g.:
Dim message = New MailMessage(sFromEmail, sToEmail)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now