Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 2-Jul-20 4:55am

The key here is
C#
mail.IsBodyHtml = True


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

or similar.
 
Share this answer
 
la solucion sensillo debes enviar un formato html como el siguiente ejemplo

DIM CONTENIDO as string = "<p>welcome to user</p><p>thank you for choosing us</p>"
Dim strarray As String =
"<html>" +
"<body> " +
" <p> Listado de cliente</p> " +
" " + CONTENTIDO + "" + tu varible debe contener <p>resultado</p>
"</body> " +
"</html> """

MAIL.Body = strarray
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900