Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple lines to body of SMTP email VB.NET

Tags:

vb.net

smtp

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("[email protected]")
        mail.To.Add("[email protected]")
        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?

like image 801
Pickle Avatar asked Apr 23 '12 15:04

Pickle


1 Answers

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()
like image 88
LarsTech Avatar answered Dec 04 '22 06:12

LarsTech