.net SMTP – Sending An Email Message With A Display Name

email-blueIf you’ve ever used .net to send email messages (and I hope you have!) you may have wanted to send the message from or to not only an address, but also include a name. The ‘display name’ is the name that appears in many email clients instead of the address (think ‘Chris Bitting’ instead of ‘cbitting@something.com’). .Net honors the email standard of “Display Name <email@domain.com>”.

Below is a quick example on how this looks in vb.net:

Dim mail As New System.Net.Mail.MailMessage("""Some Body"" <person@company.com>", """A Different Person"" <person2@company2.com>", "Subject", "Body")

Below is a full example on an email function (include Imports System.Net.Mail):

Public Function sendHTMLemail(ByVal toAddress As String, ByVal subject As String, ByVal emailBody As String) As Boolean

 Dim mail As New System.Net.Mail.MailMessage("""Chris Bitting"" <chris@chrisbitting.com>", toAddress, subject.Replace(vbTab, "").Replace(vbCrLf, ""), emailBody)
 Dim smtpMail As New System.Net.Mail.SmtpClient("yoursmtpserver.domain.com")
 'add more bcc or cc's now!
  mail.Bcc.Add("other@chrisbitting.com")

  mail.IsBodyHtml = True
  smtpMail.Send(mail)

  Return True

End Function
.net SMTP – Sending An Email Message With A Display Name

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s