【问题标题】:VB.NET: Multiple Lines in emailVB.NET:电子邮件中的多行
【发布时间】:2017-04-06 23:35:24
【问题描述】:

我尝试了以下代码的多种变体,但仍然得到相同的结果。我试图让最后一行“问题描述:....”出现在新行上。

我尝试过 vbCrLf、vbCr 和 & Environment.NewLine & _ 这些都不起作用。

还有其他人有什么建议吗?

请注意:其他电子邮件格式正确。另外,如果我在“问题标题”行的末尾添加 2 vbCr (s),那么它看起来很正常。

尤其是这个似乎是我的眼中钉。

结果:

代码:

Dim mail As New MailMessage()
Dim strbody As String

strbody = Nothing

'set the addresses
mail.From = New MailAddress("email.address@server.com")
mail.[To].Add(Email_Add)

'set the content
mail.Subject = Issue_Num & " Issue has been created."
strbody = "Your issue has been created." & vbCr & vbCr
strbody += "The Issue Team has received the following issue: " & vbCrLf
strbody += "Issue ID: " & Issue_Num & vbCrLf
strbody += "Issue Title: " & Email_Summary & vbLf
strbody += "Issue Description: " & Description & vbCrLf

mail.Body = strbody


'set the server
Dim smtp As New SmtpClient("mailhost.mailserver.com", 15)

'send the message

smtp.Send(mail)

当我使用以下代码时:

 'set the content
mail.Subject = Issue_Num & " Issue has been created."
strbody = "Your issue has been created." & vbCrLf & vbCrLf
strbody += "The Issue Team has received the following issue: " & vbCrLf
strbody += "Issue ID: " & Issue_Num & vbCrLf
strbody += "Issue Title: " & Email_Summary & vbCrLf & vbCrLf
strbody += "Issue Description: " & Description & vbCrLf

我明白了:

【问题讨论】:

  • 有什么特别的原因为什么你使用所有不同的行尾?
  • @Blindy 我刚刚将所有标签更新为 vcCrLf
  • 在这里睡 2 小时,但您的第二个输出不是您想要的吗?它与您的vbCrLf 完美匹配...

标签: vb.net smtpclient


【解决方案1】:

将邮件格式转换为 HTML,如下所示:

mail.IsBodyHtml = True

然后在要换行的地方添加一个 html 换行标签 (<br />)。

【讨论】:

    【解决方案2】:
    Message.to.Add(ToEmail)
    Message.From = New MailAddress(FromEmail)
    Message.Attachment.Add(Attachment)
    Dim body As String = "Hello user" + ","
    body += "<br /><br />"
    
    body += tbEmailBody.Text.Replace(vbCrLf, "<br />")
    'This line and the "Message.IsBodyHtml = True" are the important lines to get it to work.
    
    body += "<br /><br />"
    body += "<br /><br />Thanks"
    Message.Body = body
    Message.IsBodyHtml = True
    

    我没有看到这个确切的答案,但也许我忽略了它。 也许其他人会发现它有用 祝你好运。

    【讨论】:

      【解决方案3】:

      dim str as string

      像这样把html代码写成字符串-

      str = "<table> <tr> <td> Name : </td> <td> Yuwraj D. Bramhankar </td></tr><tr> <td> Address : </td> <td> 439, Anand Nagar, Nagpur 09 - INDIA</td></tr> </table>"
      
      
       mail.Body = str
      Dim smtp As New SmtpClient("mailhost.mailserver.com", 15)
      

      在这里发送消息

      smtp.Send(mail)
      

      【讨论】:

        猜你喜欢
        • 2012-05-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-11
        • 2012-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多