From Email

I have this Issue with the email I get it says the recipient is However I do not have the From line of code what should it be so it can read the senders email? I just have [To]

            Dim mailMessage As New MailMessage()
            mailMessage.Subject = txtSubject.Text

            mailMessage.Body = "<b>Sender Name : </b>" + txtname.Text + "<br/>" + "<b>Sender Email : </b>" + txtEmail.Text + "<br/>" + "<b>Phone : </b>" + txtPhone.Text + "<br/>" + "<b>Subject : </b>" + txtSubject.Text + "<br/>" + "<b>Company : </b>" + txtCompany.Text + "<br/>" + "<b>Items Being Shipped : </b>" + txtItembeingshipped.Text + "<br/>" + "<b>How fragile is the shipment? : </b>" + txtHowfragileistheshipment.Text + "<br/>" + "<b>What are the dimensions of the shipment? : </b>" + txtWhatarethedimensionsoftheshipment.Text + "<br/>" + "<b>How much does shipment weigh? : </b>" + txtHowmuchdoesshipmentweigh.Text + "<br/>" + "<b>Comments : </b>" + txtComments.Text + "<br/>" + "<b>Country : </b>" + ddlCountries.SelectedValue
            mailMessage.IsBodyHtml = True

            Dim smtpClient As New SmtpClient("", 25)

            Label1.Text = "Thanks for contacting us"
            Label1.ForeColor = System.Drawing.Color.Blue

            txtname.Enabled = False
            txtEmail.Enabled = False
            txtComments.Enabled = False
            txtSubject.Enabled = False
            Button1.Enabled = False
        Catch generatedExceptionName As Exception
            ' Log - Event Viewer or table 
            Label1.ForeColor = System.Drawing.Color.Blue
            Label1.ForeColor = System.Drawing.Color.Red
            Label1.Text = "There is an unknown problem. Please try later"
        End Try


Dim mailMessage As New MailMessage()

Add this:

mailMessage.From = txtEmail.Text

As an FYI, you should probably look into validating that you get a valid email address, otherwise, your code could fail.

Silly me, I forgot the MailMessage class does this automatically. It will throw an exception if it is not a valid email address.

I got this … BC30311: Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'.

Ah, yes, cause I did that too fast

mailMessage.From = new MailAddress(txtEmail.Text)

Thank You so much.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.