Send HTML Email


/ Published in: VB.NET
Save to your folder(s)

Quick function to send out decent-looking (but simple) html emails.


Copy this code and paste it in your HTML
  1. Function SendEmail(ByVal ToAddress As String, ByVal FromAddress As String, ByVal MessageSubject As String, ByVal MessageBody As String)
  2.  
  3. Dim MessageHead As String = "<html><head>"
  4. MessageHead = MessageHead & "<style>"
  5. MessageHead = MessageHead & "body {background-color:#F7F7F7; color:#000; font-family:arial,verdana,sans-serif; font-size:12px;}"
  6. MessageHead = MessageHead & "</style></head><body>"
  7.  
  8. Dim MessageFoot As String = "</body></html>"
  9.  
  10. MessageBody = MessageHead & MessageBody & MessageFoot
  11.  
  12. Dim ReturnMessage As String = ""
  13. Dim mm As New MailMessage(FromAddress, ToAddress)
  14. Dim smtp As New SmtpClient
  15.  
  16. mm.Subject = MessageSubject
  17. mm.Body = MessageBody
  18. mm.IsBodyHtml = True
  19.  
  20. Try
  21. smtp.Host = "0.0.0.0" 'ADD HOST IP
  22. smtp.Send(mm)
  23.  
  24. ReturnMessage = "Email has been dispatched"
  25.  
  26. Catch ex As Exception
  27. ReturnMessage = "We're sorry, there has been an error: " & ex.Message
  28. End Try
  29.  
  30. SendEmail = ReturnMessage
  31.  
  32. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.