Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (26 sloc) 1.11 KB
Imports System.Net.Mail
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim EmailFrom As String = "TestEmailfrom@test.com"
Dim Emailto As String = "TestEmailfrom@test.com"
Dim subject As String = "Email Template Sample"
Dim mail As New MailMessage(EmailFrom, Emailto)
mail.Subject = subject
mail.IsBodyHtml = True
mail.Body = GetEmailBody()
'// Replace placeholders in template.
mail.Body = mail.Body.Replace("<%FromName%>", txtName.Text.ToString)
mail.Body = mail.Body.Replace("<%FromCompany%>", txtCompany.Text.ToString)
'send the message
Dim smtp As New SmtpClient()
smtp.Send(mail)
Response.Write("Message Sent")
End Sub
Public Function GetEmailBody() As String
Dim templatePath As String = System.Web.HttpContext.Current.Server.MapPath("~/ContactForm.txt")
Dim sr As New StreamReader(templatePath)
Return sr.ReadToEnd()
End Function
End Class