电子邮件换行符不起作用

Email line breaks not working

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

我参考了很多例子,比如"Adding multiple lines 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.")
    
  2. 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
    
  3. vbNewLine

    strbody = strbody & "Thank you and have a wonderful day. " &  vbNewLine
    
  4. vbCrLf

    strbody = strbody & "Thank you and have a wonderful day. " & vbCrLf
    
  5. Environment.NewLine

    strbody = strbody & "Thank you and have a wonderful day. " & Environment.NewLine
    

等等,但每次我收到的邮件都没有换行符。

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

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

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

msg.IsBodyHtml = True

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

strbody = strbody & "Thank you for contacting us to gain account access. <br><br>"

您正在使用 html 模板吗?

试试

strbody = strbody & "Thank you and have a wonderful day. <br>" 

或\n

strbody = strbody & "Thank you and have a wonderful day. \n"