Link to home
Start Free TrialLog in
Avatar of Bakersville
BakersvilleFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Insert into a databse through an email using ajax

Hi all

I was wondering if anyone has ever tried or knows how i can update/insert a record directly from an email.

Break down.

I have got an email i want to send out with thre options on it,

Good
Okay
Bad.

All i want the receiver to do is to click on a link the will update my database with their click on it. Without taking them to a webpage.

So if i take the javascript for updating a record with refreashing the page, surely it should work, but it does not.

Can anyone tell me how to do this.

Thank you in advance
Baker

p.s. code below on what i am using
<script type="text/javascript">
<!--
function InsertItem(str,str1) {
//document.SampleForm.myText.value = document.SampleForm.myText.value.toUpperCase()
//Firstly go to collect data for transmitting to webpage
      var xmlhttp; 

if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) 
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("get","http://www.mydomain.co.uk/Replies/reply.aspx?P="+str+"&R="+str1,true); 
    xmlhttp.send();
}
-->
</script>
<a href="javascript:InsertItem('1','Good')">Good</a><br /><a href="javascript:InsertItem('1','Okay')">Okay</a><br /><a href="javascript:InsertItem('1','Bad')">Bad</a><br /><br /><br /><br /><div id="txtHint">Nothing Said</div><br />

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

There  needs to be something parsing the email content - is there?
Avatar of Bakersville

ASKER

I am sorry, you have lost me.  Newbe to this kind of thing
What is reading the email?
I was hoping for a asp.net page to listen for the action. If thats what you mean?


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        
        


        Dim conn As SqlConnection

        conn = New SqlConnection("Data Source=SERVER;Initial Catalog=DB;Persist Security Info=True;User ID=sa;Password=~S0l1hull")

        Dim sqlIns As String = "INSERT INTO dbo.FeedBackEmailTest (Person1, Reply1) VALUES (@Person1, @Reply1)"

        conn.Open()
        Try
            Dim cmdIns As New SqlCommand(sqlIns, conn)
            cmdIns.Parameters.Add("@Person1", SqlDbType.NVarChar).Value = Request.QueryString("P")
            cmdIns.Parameters.Add("@Reply1", SqlDbType.NVarChar).Value = Request.QueryString("R")
            cmdIns.ExecuteNonQuery()
            cmdIns.Dispose()
            cmdIns = Nothing
        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            conn.Close()
        End Try

Response.Write("Person : " & Request.QueryString("P") & "<BR>Said : " & Request.QueryString("R"))


    End Sub

Open in new window

Can you send me one of the emails?
OK, what is your email address?
dave@dacservices.co.uk
Oh i see: the link is in an email. Quite a lot of email clients won't permit javascript, so you're better off simply using ordinary links
daveamour: email sent
CEHJ:

How would you suggest i do it? Or even better can you show/give me examples?

Baker
I think CEHJ is right - any concerns with just using a normal link?
My boss does not it going of anywhere.

But if that is the only way then i will have to thnk of another solution
You don't need script. Look at the source code of any mail that you've got that contains a link you can click
Avatar of colr__
colr__

Standard email clients (including Outlook) will not allow Javascript in a message as stated above, so this is a non starter. There are a couple of options available:

1) Have the link point to a server resource that when hit, will update the database. This does mean that a web page will open though. You could have the web page close itself automatically when it is rendered, but it would still pop the browser up in front of the user

2) You could maybe have the links that use mailto: so when the user clicks on one of them, a new prepopulated email opens which the suer just has to send. Have this email sent to a mailbox that is monitored by some java code, that would look at the incoming mails and update the database accordingly. This is the only way i can think of that would avoid opening a browser.
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, can not be done