Pickle Pickle - 2 years ago 160
Vb.net Question

Adding multiple lines to body of SMTP email VB.NET

I can use this code to send an email on my Exchange server

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.Subject = "Equipment Request"
mail.Body = "This is for testing SMTP mail from me"


catch ex As Exception
End Try

But how can I add multiple lines to the body?

Answer Source

Just treat it like a normal text object where you can use Environment.NewLine or vbNewLine between sentences.

StringBuilder is useful here:

Dim sb As New StringBuilder
sb.AppendLine("Line One")
sb.AppendLine("Line Two")

mail.Body = sb.ToString()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download