gpt4 book ai didi

vb.net - 电子邮件换行符不起作用

转载 作者:行者123 更新时间:2023-12-04 22:41:57 29 4
gpt4 key购买 nike

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

我引用了很多例子,比如"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>"

关于vb.net - 电子邮件换行符不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33282904/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com