Send Link within an Email from a Webpage

Posted on 2008-02-07
Medium Priority
Last Modified: 2011-09-20
Visual Studio 2005 Pro
SQL Server 2005
C# Programming
Web Project

Within my project, a user can fill out a request. After they save the request to the database, I want to send an email to their supervisor (pulled from a user database). In this e-mail, I want to send a link that will send them to an approval page along with the request number.

I can't seem to find anything on this -- I've seen some PHP forms that MIGHT have it, but I've never even heard of PHP (well, NOW I have).

Is there any way to compose an e-mail from the Web page that can pull these variables and put them in an e-mail message?

I haven't written any code, or I would attach it. :-)

Thanks for any help on this!
Question by:alghawks
  • 4
  • 3

Expert Comment

ID: 20846067
You need to create an e-mail in C# on the form submission and you can compose the body of the e-mail and input the link, here's a general link about creating an e-mail in C#: http://www.devx.com/tips/Tip/29291

Author Comment

ID: 20846130
Except for two things:

1. The warnings come up that System.web.mail is obsolete so you need to use System.net.mail

2. This doesn't address putting the link in there with the message body. It just has put the body here. That I saw on the crummy MSDN alleged "help" pages on mail.

As I stated, I need to know how to put the link in the message body, including the ID of the just-added request.
LVL 12

Expert Comment

ID: 20856101
I believe the system.web.mail is obsolete is only a warning, it should still let you compile and it should run fine. Do you know how to read information from the database? If you do you would build the hyperlink string while reading information from the database, something like
  myLInk = "<a href=""http://www.mysite.com/default.aspx?name" & reader("employee_name") & "> my link click here </a>";
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.


Author Comment

ID: 20866378
I would frown on a programmer who knowingly put obsolete programming in a brand new system, so I will not be using system.web.mail.

I guess I don't understand your question about reading from the SQL database. Well, I know I don't because the "reader.read" makes absolutely no sense to me. However, I'm pretty sure it isn't relevant to my question.

This is what I'm trying to do:

The user will update or insert a new request on a web page. On this request page is an ID number which will be stored on the SQL Database, but it is still on the web page in a TextBox (or label for changes because they cannot change the ID once it is inserted).

After they save their changes or new request, I want the program to send an e-mail notification to their supervisor advising them they need to go and approve or deny the request All I want to include in the link is an ID number taken directly from the web page. I want them to click on the link in their e-mail and have it take them to the approval page with the information for that particular ID pulled up.

I cannot possibly be the only one who has ever wanted to do this. I have gotten e-mails: "click here to confirm" and when I get there, it knows who I am. However, I cannot locate the page from which these come to see the coding.
LVL 12

Expert Comment

ID: 20869860
Yeah. Well is there a reason you can't use System.Net.Mail instead of System.Web.Mail. I thought it was already implemented and you were having problems compiling system.web.mail. The other namespace should suffice. When you are generating the email with this namespace you will be given them oppurtunity to add text as part of the email body. It is during this step that you will be able to add the "click here to confirm" link in which you will add some kind of querystring value to the link so it will read: <a href="http://www.mysite.com/default.aspx?id=1234&key=444553"> click here to confirm </a> you will need to give each confirmation its own identitiy so when they click the link you will be able to assess where it came from. I assumed it would be stored in the database. It is commons to record the identity of the email in the database when the email is generated and then when the email link is clicked the identity is looked up and confirmed or outputs a message saying it has already been confirmed.

Author Comment

ID: 20869912
Perhaps I'm not communicating well. Maybe I'll just try another forum. Thanks anyway.
LVL 12

Accepted Solution

lunadl earned 900 total points
ID: 20870096
No, it is probably me that is not communicating correctly. You will need two pages. One that will send the email out and one that will be a landing page for when the link is clicked. You can name them
sendemail.aspx and confirm.aspx . sendemail.aspx will create an email using system.net.mail. In order for the user to confirm the email you will have to have a unique identifier. It can be the request id if there is one in the database you are already using. Also you will have a column in your db that says whether or not it has been confirmed so it can be changed when a user goes to this page. Sending the email will be as follows:
MailMessage message = new MailMessage(
               "Subject line.",
               "<a href="http://www.mysite.com/default.aspx?request=" &  requestID & "> click here to confirm </a>");
SmtpClient client = new SmtpClient(server);

Your landing page will be as follows:
myval = Request.QueryString("requestID"); //The Querystring is part of the link from above and will give you the id you need to update the db

Let me know if I'm not being clear or what it is i'm missing.

Author Closing Comment

ID: 31429031
I assume this will work (once I switched the double quotation marks for singles within the body) -- I'm now dealing with (what I assume will be) security errors (exception:Failure sending mail) which I assume will be system specific and I'll have to ask around here.

Thanks for sticking with it!!! And thanks for the code explanation!

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question