将多行添加到 SMTP 电子邮件 VB.NET 的正文 [英] Adding multiple lines to body of SMTP email VB.NET
本文介绍了将多行添加到 SMTP 电子邮件 VB.NET 的正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用此代码在我的 Exchange 服务器上发送电子邮件
I can use this code to send an email on my Exchange server
Try
Dim SmtpServer As New SmtpClient
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential()
SmtpServer.Port = 25
SmtpServer.Host = "email.host.com"
mail = New MailMessage
mail.From = New MailAddress("myemail@email.com")
mail.To.Add("otheremail@email.com")
mail.Subject = "Equipment Request"
mail.Body = "This is for testing SMTP mail from me"
SmtpServer.Send(mail)
catch ex As Exception
MsgBox(ex.ToString)
End Try
但是如何在正文中添加多行?
But how can I add multiple lines to the body?
推荐答案
把它当作一个普通的文本对象,你可以在句子之间使用 Environment.NewLine
或 vbNewLine
.
Just treat it like a normal text object where you can use Environment.NewLine
or vbNewLine
between sentences.
StringBuilder
在这里很有用:
Dim sb As New StringBuilder
sb.AppendLine("Line One")
sb.AppendLine("Line Two")
mail.Body = sb.ToString()
这篇关于将多行添加到 SMTP 电子邮件 VB.NET 的正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文