Click here to Skip to main content
13,632,434 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have 2 text boxes for the user to enter the mail subject and mail body.

when he enters the title and body and save they will store in the database.


when he wants to send an email then he will retrieve the title and body from the database and sends an email

Everything is working and we can able to send the mail to the user.

But when the user enters the bodylike below and save in the database it is saved in the string datatype

welcome to user
thank you for choosing us
we are glad to have you
thanks

when we retrieve the body from the database and sent the mail then the mail is like below
welcome to user thank you for choosing us we are glad to have you thanks


is there anyway to format the body and sent as it is the user enters in the texbox

thanks in advance

What I have tried:

Dim Fromemail As String = dt.Rows(0)("email").ToString()
                Dim password As String = dt.Rows(0)("password").ToString()
                Dim mailsubject As String = dt.Rows(0)("title").ToString()
                Dim mailbody As String = dt.Rows(0)("body").ToString()
                Dim portno As Integer = dt.Rows(0)("portno")
                Dim mail As MailMessage = New MailMessage

                mail.From = New MailAddress(Fromemail)
                mail.To.Add(New MailAddress(Toemail))
                mail.Subject = mailsubject
                mail.Body = mailbody

                mail.IsBodyHtml = True

                Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", portno)
                client.EnableSsl = True
                client.UseDefaultCredentials = False
                client.Credentials = New System.Net.NetworkCredential(Fromemail, password)
                Try
                    client.Send(mail)
                    MessageBox.Show("Email Sent Successfully")
                Catch ex As Exception
                    MessageBox.Show("Sending email failed. Please Try again")
                End Try
Posted 9-Nov-17 20:07pm
Updated 9-Nov-17 20:27pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The key here is
mail.IsBodyHtml = True


HTML needs tags for formatting, it doesn't respect CRLF characters,
You could try
mail.Body = mailbody.Replace("\n", "<br />");

or similar.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.180712.1 | Last Updated 10 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100