电子邮件换行符不起作用

nar*_*992 3 vb.net email line-breaks

我试图在自动电子邮件的正文中强制换行。

我参考了很多例子,例如“Adding multiplelines to body of SMTP email VB.NET”

我尝试了许多不同的方法来进行换行:

  1. 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.")
    
    Run Code Online (Sandbox Code Playgroud)
  2. 系统.环境.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
    
    Run Code Online (Sandbox Code Playgroud)
  3. vb换行符

    strbody = strbody & "Thank you and have a wonderful day. " &  vbNewLine
    
    Run Code Online (Sandbox Code Playgroud)
  4. 铬铬

    strbody = strbody & "Thank you and have a wonderful day. " & vbCrLf
    
    Run Code Online (Sandbox Code Playgroud)
  5. 环境.NewLine

    strbody = strbody & "Thank you and have a wonderful day. " & Environment.NewLine
    
    Run Code Online (Sandbox Code Playgroud)

等等,但每次我收到电子邮件时都没有换行。

还有其他版本我可以测试吗?

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 from@location.com of your concern "


    strTo = Dsa.Tables(0).Rows(0).Item(1)
    Dim msg As New System.Net.Mail.MailMessage("from@we-location.com", 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
Run Code Online (Sandbox Code Playgroud)

N0A*_*ias 5

这里的关键代码行是这样的:

msg.IsBodyHtml = True
Run Code Online (Sandbox Code Playgroud)

由于您要发送 HTML 电子邮件,因此必须使用 HTML 标记来创建换行符。

strbody = strbody & "Thank you for contacting us to gain account access. <br><br>"
Run Code Online (Sandbox Code Playgroud)