<?php
$system = $_POST['system']; // The FreshBooks system
$name = $_POST['name']; // The name of the event that just happened, e.g.invoice.create
$id = $_POST['object_id'];
$subject = "[$system] Event: $name";
if ($name=='callback.verify') {
$body = "
$name just happened on $system
Verification token: ".$_POST['verifier']."
";
} else {
$body = "
$name just happened
on $system
for id: $id
";
}
mail('[email protected]',$subject,$body);
?>
views:
112answers:
3
A:
First we have a standard ASPX page listening for people to post to it. (You could also use a ASHX handler but I won't get into that)
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Net.Mail"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/C#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
var systemValue = Request.Form["system"];
var nameValue = Request.Form["name"];
var idValue = Request.Form["object_id"];
var verifierValue = Request.Form["verifier"];
var subject = string.Format("{0} Event: {1}", systemValue, nameValue);
string body;
if ( nameValue.Equals("callback verify", StringComparison.OrdinalIgnoreCase) )
body = string.Format("\n{0} just happened on {1}\n\nVerification token: {2}\n", nameValue, systemValue, verifierValue );
else
body = string.Format("\n{0} just happened on {1} for id: {2}\n", nameValue, systemValue, idValue);
var email = new MailMessage(
new MailAddress( "[email protected]")
, new MailAddress( "[email protected]") )
{
Subject = subject, Body = body
};
var smtpServer = new SmtpClient();
smtpServer.Send( email );
}
</script>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
Now, somewhere else, presumably in your postbin.org page, you need an HTML page that posts to another. Something like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="Default.aspx" method="post">
<input type="text" id="system" name="system" />
<input type="text" id="name" name="name" />
<input type="text" id="object_id" name="object_id" />
<input type="text" id="verifier" name="verifier" />
<input type="submit" />
</form>
</body>
</html>
In this standard Html page, I'm setting the form action to post to my ASPX page. When that happens, the Page_Load event on the ASPX page will fire and send the email (assuming the email settings are configured in the ASPX page's web.config file).
Thomas
2010-03-25 15:54:49
How would I put this into a web or windows service to read from postbin.org for example?
Xaisoft
2010-03-25 16:27:11
This could be done via a code-behind page on a basic ASP.NET page or done via a handler page.
Thomas
2010-03-25 16:34:12
ok in my code behind, how would i tell it that i want it to read request from postbin.org
Xaisoft
2010-03-25 16:47:04
You would post *to* the page that contains the above code-behind from somewhere else. When that happens, the above code will read the post via Request.Form.
Thomas
2010-03-25 16:59:55
Expanding a bit, your postbin.org needs to post to an ASP.NET aspx page that contains the above code in say its Page_Load event.
Thomas
2010-03-25 17:01:31
I kind of understand that, but I am not sure how to set it up.
Xaisoft
2010-03-25 17:05:09
Updated my post to better explain.
Thomas
2010-03-25 17:45:53
Ok that is a better explanation, so basically I need postbin.org to post to my aspx page, I can just read directly from postbin.org
Xaisoft
2010-03-25 18:02:31
Correct. Said another way, you can read from anything that posts to the aspx page including postbin.org.
Thomas
2010-03-25 18:06:52
A:
To get the request values you would do something like this
string myValue = Request.Form["MyPostArgument"];
You can then use the string.format class to setup the messages
string subject = string.format("{0} Event: {1}", mySystem, myEvent);
You then need to use the SmtpClient and MailMessage objects to build out the e-mail.
Mitchel Sellers
2010-03-25 15:55:52