473,326 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

embedding variables in email body

I am creating an email message to be sent from a web page. How do I embed
variables like strFirstName, strLastName etc. into the body

I would like it to say.

Last Name : strLastName ex. Gower
First Name: strFirstName ex. Bill

Dim strFirstName As String = CType(Request.QueryString("FirstName"), String)

Dim strLastName As String = CType(Request.QueryString("LastName"), String)

Dim objMailMessage As Mail.MailMessage

SmtpMail.SmtpServer = "mailhub.mysite.com"

objMailMessage = New Mail.MailMessage

objMailMessage.From = "my*****@mysite.org"

objMailMessage.To = "yo*******@yoursite.org"

objMailMessage.Subject = "A Member has made the following changes to their
personal information"

objMailMessage.Body = ""

SmtpMail.Send(objMailMessage)
Nov 19 '05 #1
2 2069
William Gower wrote:
I am creating an email message to be sent from a web page. How do I
embed variables like strFirstName, strLastName etc. into the body


objMailMessage.Body = "Dear " & _
Server.HtmlEncode(Request.QueryString("FirstName") ) & " " & _
Server.HtmlEncode(Request.QueryString("LastName")) & ",\n" & _
"How do you want your Spam sent to you today? ;-)"

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP


Nov 19 '05 #2
As Carl pointed out, you're just smithing a string and setting the .Body
property.

If you have a lengthy body, you might benefit from using the
System.Text.StringBuilder class instead, doing a bunch of .Append () and
..AppendFormat () 's to create your body, and then set the email object's
..Body to the StringBuilder.ToString () result;

using System.Text;

StringBuilder sb = new StringBuilder ();
sb.Append ("Dear {0} {1},\n",
Request.QueryString("FirstName"),
Request.QueryString("LastName"));
sb.Append ("\n");
sb.Append ("How do you want your Spam sent to you today? ;-)");
objMailMessage.Body = sb.ToString ();

Make sure to do HtmlEncodes and to do your necessary HTML formatting if you
want the message body to be HTML.

An alternative is to use a product like AspNetEmail;

http://www.aspnetemail.com/

Out of the box, this gives you two alternatives to building your email body
in code;

1) built-in mail-merging through templates.

2) the ability to send a webpage as the email body content. This lets you
design and code your email body as a standard ASPX page, complete with
databound controls, calculations, etc. When you send the message,
AspNetEmail makes a request to your page and generates the email content on
the fly.
/// M


"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in message
news:eL**************@TK2MSFTNGP15.phx.gbl...
William Gower wrote:
I am creating an email message to be sent from a web page. How do I
embed variables like strFirstName, strLastName etc. into the body


objMailMessage.Body = "Dear " & _
Server.HtmlEncode(Request.QueryString("FirstName") ) & " " & _
Server.HtmlEncode(Request.QueryString("LastName")) & ",\n" & _
"How do you want your Spam sent to you today? ;-)"

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Wilcox | last post by:
I have the following two files used to insert data into a database. when meinsert.php is executed a blank record is inserted in the database as if the .php file is not receiving the variables. ...
0
by: jordi | last post by:
Hi, I'm starting to use Python embedded in a C program. I'm using Python to execute several scripts using as a variables information retrieved for several multithread "agents" written in C. ...
0
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to...
4
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been...
2
by: katekukku | last post by:
HI, Could anyone please tell me what are static variables and what exactly are there features. I am a little bit confused. Thank You
3
by: Tim T | last post by:
Hi, I hope there is someone reading this that has the answer, Please Help! I have the need to send a html email via asp.net. its easy enough to send an html email and add attachments. My...
3
by: jethro_uk | last post by:
Hi there, I have a bizarre problem with FORM variables in ASP. Scenario using VI6, IE6, Windows2000 server: MyPage.ASP: .. .. ..
6
by: christopher.j.just | last post by:
I need to set the information being passed through the fields (23 of them) in the form into a session. Where do I start? Thanks, Chris
7
by: pavan anumula | last post by:
I have a requirement When i click on button, i have to initiate an email with the to address, subject, and body should contain an image and the text . Problem : I cannot embed the image using...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.