Hey everyone,
I am trying to send an email and I never receive it, but I do get a message when I debug that:
"Property access must assign to the property or use its value."

Here is my VB code:

Imports System.Web.Mail

'Send email confirming purchase
            Dim notification As New Net.Mail.MailMessage()
            Dim mSmtpClient As New Net.Mail.SmtpClient()

            notification.From = New Net.Mail.MailAddress("itintern@edc.org")
            notification.To.Add(New Net.Mail.MailAddress(txtEmail.Text))
            notification.Subject = "Purchasing order " & lblOrderNumber.Text
            notification.Body = "Purchasing order " & lblOrderNumber.Text & " is being processed and is in the approval process now. You will receive an email notifying you if your purchase was approved or was not approved shortly."
            mSmtpClient.Send(notification)

and here is my code in my Web.config file:

<system.net>
    <mailSettings>
      <smtp from="itintern@edc.org">
        <!-- This is simply for testing purposes - Sam's personal account -->
        <network host="server" userName="username" password="secret" port="25" defaultCredentials="true" />
      </smtp>    
    </mailSettings>
  </system.net>
Const SMTPHost As String = "Your.ExchangeServer" 

    Public Sub SendMailMessage(ByVal from As String, ByVal recepient As String, ByVal bcc As String, ByVal cc As String, ByVal subject As String, ByVal body As String)
        Try
            'create the mail message
            Dim mail As New Net.Mail.MailMessage()
            'set the addresses
            mail.From = New Net.Mail.MailAddress(from)
            mail.To.Add(recepient)
            'set the content
            mail.Subject = subject
            mail.Body = body
            mail.IsBodyHtml = True

            'send the message
            Dim smtp As New Net.Mail.SmtpClient(SMTPHost)
            'smtp.
            smtp.UseDefaultCredentials = True
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network
            If Not smtp Is Nothing Then
                smtp.Send(mail)
            End If
        Catch ex As Exception

        End Try


    End Sub

Thanks, but this still will not send me an email. I tried removing the if-statement because I assumed it was never entering it, but then I got the property access... error again.

Any other ideas?

Ok, let's make it real simple for the moment. Try this

Imports System.Web.Mail
Dim message As New MailMessage("sender@address", "from@address", "Subject", "Message Text")
Dim emailClient As New SmtpClient("itintern@edc.org")
emailClient.Send(message)

For the moment, don't replace the "Subject" or the "Message Text" with textbox.text values... just change the sender and from addresses - and try it out. This will tell us whether or not the issue is related to the textbox somehow, ok... we want to get the textbox.text out of here for the moment.

If you don't get the error again, then you know that the textbox.text values are the problem. The code I sent to you works fine at numerous sites... so I'm a bit at odds to see what exactly the issue is, but this will at least eliminate part of what could be going on.

I found the solution. I needed to upload my project to the company database so that it could connect to their system. Before it was trying to connect to mine, which did not have the correct credentials. Thanks for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.