System.Net.Mail & additional fields

Posted on 2008-11-19
Last Modified: 2012-06-27
I understand how to send mail using MailMessage, but what if I want to add additional fields to the body of the email, say a telephone and fax number, or any number of fields?  I think it should go in the body, but I am not getting all to show correctly on the email.  Can someone explain how I might expand what can be sent in the email body?  Below is the code I am starting with.

Using .NET 2.0 and VB.

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

        'Email address to send contact for to

        Const ToAddress As String = ""


        'Create the MailMessage instance

        Dim mm As New MailMessage(tbEmail.Text, ToAddress)

        'Assign the MailMessage's properties

        mm.Subject = dlSubject.Text

        mm.Body = tbComments.Text

        mm.IsBodyHtml = False

        'Create the SmtpClient object

        Dim smtp As New SmtpClient

        'Send the MailMessage using the Web.config settings)


        'Show the EmailSentForm Panel and hide the EmailForm Panel

        EmailSentForm.Visible = True

        Me.contactform.Visible = False

        'ContactForm.Visible = False

Open in new window

Question by:simprick
    LVL 13

    Accepted Solution

    Mail body will take a string (plain text or HTML) that will be displayed as the email message.

    If you want to include more data in the email body you can construct a string that includes all the data to be displayed and in the specific format and finally assign the string to mail body.

    Something like below

    dim mailbody as string
    mailbody = tbComments.Text & Environment.NewLine
    mailbody &= "Telephone number : " & txtTelephoneNumber.Text & Environment.NewLine
    mailbody &= "Address : " & txtAddress1.Text & Environment.NewLine

    If you want to have more control over the mail body you can use HTML format
    mailbody &= "<b>Telephone Number :  </b>" & txtTelephoneNumber.Text & "<br/>"

    then you have to set mm.IsBodyHtml = true
    LVL 2

    Author Closing Comment

    Thanks much, I think html will be they way to go on the final product.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now