Reputation: 1203
I am trying to force line breaks inside the body of my automatic email.
I have referenced many examples, such as "Adding multiple lines to body of SMTP email VB.NET".
I've tried many different ways to make line breaks:
StringBuilder.AppendLine
Dim sb As New StringBuilder
sb.AppendLine("For security purposes, only the password will be provided within this email.")
sb.AppendLine("Thank you and have a wonderful day.")
System.Environment.NewLine
strbody = strbody & "Thank you and have a wonderful day. " & System.Environment.NewLine
strbody = strbody & "Password: " & Dsa.Tables(0).Rows(0).Item(2) & System.Environment.NewLine & System.Environment.NewLine
vbNewLine
strbody = strbody & "Thank you and have a wonderful day. " & vbNewLine
vbCrLf
strbody = strbody & "Thank you and have a wonderful day. " & vbCrLf
Environment.NewLine
strbody = strbody & "Thank you and have a wonderful day. " & Environment.NewLine
and so on, but every time I receive the email there are no line breaks.
Is there any other versions I can test?
Dim strbody As String
Try
Dim strTo As String
strbody = ""
strbody = strbody & "Thank you for contacting us to gain account access. " & vbNewLine
strbody = strbody & "You requested your password for the Applicaton registration site. " & vbNewLine
strbody = strbody & "For security purposes, only the password will be provided within this email. " & vbNewLine
strbody = strbody & "Thank you and have a wonderful day. " & vbNewLine
strbody = strbody & "Password: " & Dsa.Tables(0).Rows(0).Item(2) & System.Environment.NewLine & vbNewLine & vbNewLine
strbody = strbody & "If you didn't request your password, please notify [email protected] of your concern "
strTo = Dsa.Tables(0).Rows(0).Item(1)
Dim msg As New System.Net.Mail.MailMessage("[email protected]", strTo, "Retrive Your Password", strbody)
Dim smtp As New System.Net.Mail.SmtpClient
msg.IsBodyHtml = True
smtp.Host = "mailhost.location.com"
smtp.Send(msg)
Catch ex As Exception
End Try
Upvotes: 3
Views: 1848
Reputation: 117
Are you working with a html template?
Try with
strbody = strbody & "Thank you and have a wonderful day. <br>"
or \n
strbody = strbody & "Thank you and have a wonderful day. \n"
Upvotes: 3
Reputation: 9193
The key line of code here is this:
msg.IsBodyHtml = True
Since you are sending an HTML email you must use HTML markup to create line breaks.
strbody = strbody & "Thank you for contacting us to gain account access. <br><br>"
Upvotes: 5