I want to send emails with variables embedded in them to change the information within as needed. First I wrote basic HTML email code without variables and it worked. Then I tried to add variables but it didn't work.
This is the code that didn't work (just one of the ways I tried to add a variable):
I also tried <% Username %> in the non-working code as wellCode:Try Dim emailmessage As New MailMessage emailmessage.To.Add("to email address") emailmessage.From = New MailAddress("from email address") emailmessage.Subject = ("Arrival Date") emailmessage.IsBodyHtml = True Dim Username as string = "Bill" Dim NewString As String = "<html> <body> <p>Dear " + UserName + ", </p> <p>I will be arriving on the 5th</p> <p>Sincerely,<br>-Sam</br></p> </body> </html> " Dim SMTP As New SmtpClient() SMTP.Host = "SMTP.Gmail.com" SMTP.Port = 587 SMTP.EnableSsl = True SMTP.Credentials = New Net.NetworkCredential("email from", "password") SMTP.Send(emailmessage) Catch ex As Exception MsgBox(ex.ToString) End Try
This code does work but is strictly text:
I have been working on this all afternoon and evening and have searched the internet with no solution.Code:Try Dim emailmessage As New MailMessage emailmessage.To.Add("to email address") emailmessage.From = New MailAddress("from email address") emailmessage.Subject = ("Arrival Date") emailmessage.IsBodyHtml = False Dim Username As String = "Bill" Dim Body As String = "Hi " + Username + ", I'll be arriving on the 5th" " emailmessage.Body = Body Dim SMTP As New SmtpClient() SMTP.Host = "SMTP.Gmail.com" SMTP.Port = 587 SMTP.EnableSsl = True SMTP.Credentials = New Net.NetworkCredential("email from", "password") SMTP.Send(emailmessage) Catch ex As Exception MsgBox(ex.ToString) End Try
Please point me in the right direction.
Thanks




Reply With Quote
