Sending mail using flash and asp.net
Tuesday, November 24, 2009
This article decribes how to send mail from a Flash UI using asp.net. Create a UI like this in flash.

Assign an instance name of the 'Send' movie clip as'myButton'. Also name the text box as 'email'. On the first frame action, write the action script code.

var loadvar=new LoadVars(); //to send variables
var receiveLoad = new LoadVars();//to receive the response


receiveLoad.onLoad=function(success)
{
if(success)
{
trace(unescape(receiveLoad.toString()));//if received succesfully
}
else
{
trace("error");
}
}

this.myButton.onRelease=function(){ //myButton click event


if (email.text.indexOf(" ") != -1 || email.text.indexOf("@") == -1 || email.text.indexOf(".") == -1 ||email.text.length<6||email.text.lastIndexOf(".") {
res="validateion error";
return false;
} //email validation



if(email.text!=""){

loadvar.customp=escape(email.text);//send a variable customp

var url="http://YOUR SERVER NAME/SendMail.ashx?cb="+(Math.round(Math.random()*96584674));//cb-cache burst used to explicitly send new urls so that the request is not cached

loadvar.sendAndLoad(url,receiveLoad,"POST");
}
}

The LoadVars object is an alternative to the loadVariables action for transferring variables between a Flash movie and a server. It uses the methods load , send , and sendAndLoad to communicate with a server.


In Asp.NET create a generic handler with name 'SendMail.ashx' . Write the code to send email in the handler file.

<%@ WebHandler Language="C#" Class="SendMail" %>

using System;
using System.Web;
using System.Net.Mail;
using System.Text.RegularExpressions;

public class SendMail : IHttpHandler {

public void ProcessRequest (HttpContext context) {

string emailId = string.Empty;

if (context.Request["customp"] != null)
{
emailId = HttpUtility.UrlDecode(context.Request["customp"].ToString());
}

if ((emailId != "") && Regex.IsMatch(emailId, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")) //check for a valid emailid
{
SmtpClient smtpClient = new SmtpClient();
MailAddress mailFrom = new MailAddress("YOUR EMAIL ID");
MailAddress mailTo = new MailAddress(emailId);
MailMessage mailMessage = new MailMessage(mailFrom, mailTo);
mailMessage.Subject = "Test Mail";
mailMessage.Body = "This is a test mail sent using Flash 8";
mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
smtpClient.Host = "YOUR MAIL SERVER HOST NAME";
smtpClient.Port = YOUR PORT NO;
smtpClient.Credentials = new System.Net.NetworkCredential("YOUR USERNAME", "YOUR PASSWORD");
try
{
smtpClient.Send(mailMessage);
context.Response.Write("&res=1");
}
catch (Exception exException)
{
context.Response.Write("&res="+exException.ToString());
}
}
else
{
context.Response.Write("&res=2");
}

}

public bool IsReusable {
get {
return false;
}
}

}


When executed the loadvar variable posts a request to the sendmal.ashx file with the emailid which inturn sends the mail.

Labels: , , , , , ,

 
posted by Abhijeet at 8:39 PM | Permalink | 0 comments
Custom Splash screen for Silverlight applications
Monday, August 24, 2009


Is the in-stock splash screen in Silverlight application boring you? Here is an easy way to create custom splash screens for your Silverlight application. Essentially the splash screen itself is an XAML file with the desired graphical content and the download progress of the XAP can be tracked using a little javascript code. As the C# managed enironment has not been loaded we can't use C# code to track the progress. Also the XAML file should not be the part of the XAP file as it has to be displayed while the XAP is been loaded.


To craete a custom splashscreen lets first start a Silverlight project with ASP.NET test website.Then, add a new XAML file to your ASP.NET website (not the Silverlight project). To do so, select the ASP.NET website in the Solution Explorer and choose Website > Add New Item. Choose the Silverlight JScript page template, enter a name(CustomSplashScreen.xaml here), and click Add. This XAML file will hold the markup for your splash screen. In our application we are creating XAML like this to build a custom splashscreen like the image below.


<Grid xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Grid >
<Rectangle x:Name="progressBarBackground" Fill="White" Stroke="Black"
StrokeThickness="1" Height="30" Width="200" Grid.Row="1"></Rectangle>
<Rectangle x:Name="progressBar" Fill="Yellow" Height="28" Width="0"
Grid.Row="1" HorizontalAlignment="Left">
</Rectangle>
</Grid>
<TextBlock x:Name="progressText" HorizontalAlignment="Center"
Text="0% downloaded ..."></TextBlock>
</StackPanel>
</Grid>

Next we need to add a little javascript code to track the progress of the XAP file. the event looks like this


<script type="text/javascript">
function onSourceDownloadProgressChanged(sender, eventArgs)
{
sender.findName("progressText").Text = Math.round((eventArgs.progress * 100)) + "% downloaded ...";
sender.findName("progressBar").Width = eventArgs.progress * sender.findName("progressBarBackground").Width;
}
</script>



Also add the following parameters to the <object> tag


<param name = "splashscreensource" value = "CustomSplashScreen.xaml" />
<param name = "onsourcedownloadprogresschanged" value = "onSourceDownloadProgressChanged" />

The parameter 'splashscreensource' is used to identify the splash screen and 'onsourcedownloadprogresschanged' is used to hook up the javascript event.

If instead of <object> tag Silverlight web control is used , it also has two similiar properties named 'SplashScreenSource' and 'OnSourceDownloadProgressChanged'.

Example


<asp:Silverlight ID="silverlightControl" runat="server"
Source="~/ClientBin/MyApp.xap" Version="2.0" Width="800" Height="500"
SplashScreenSource="~/CustomSplashScreen.xaml"
OnSourceDownloadProgressChanged= "onSourceDownloadProgressChanged" />

To test the application add some large mp3 files and set the build action of each one to Resource so it’s added to the XAP file and will be downloaded slowly in the local system.

Labels: , , , , , ,

 
posted by Abhijeet at 4:31 AM | Permalink | 0 comments
Submit Silverlight games and earn money from Adsense Revenue Sharing
Sunday, July 26, 2009
Happy news for all Silverlight game developers. If your are a Silverlight developer, submit your Games and other interesting Silverlight applications in SilverlightClub.Com . You can earn 90% of the Google AdSense revenue from your Game hosting pages, for 1 to 3 years depending on the quality and popularity of your game.

You may submit games and other interesting applications developed using Microsoft Silverlight technology. You must upload the .xap file and a screenshot of your application.

The following application types are allowed:

1. Games
2. Puzzles
3. Entertainment for Kids - Painting, Magic, Tricks
4. Learning activities
5. Other Fun/entertainment applications

SilverlightClub.Com
follows a revenue sharing model based on Google AdSense API revenue sharing system.

In order to participate in this program, you must have a Google AdSense account. If you do not have one, you may create a Google AdSense account through SilverlightClub.com.

If your application is approved and published there, you will get 90% of the revenue from Google AdSense directly to your AdSense account. Remaining 10% of the revenue will be credited to SilverlightClub.Com's AdSense account. It is managed, tracked and paid by Google.


You must have/get an approved AdSense account to participate in revenue sharing.

By default, you will get 90% revenue share from your hosted application pages for a period of 1 year. In case of applications hosted exclusively in this site or applications that have no reference to your own website, they can extend this period to 2 or more years.

I submitted my first game, BubbleBreaker in their site. Click here to submit your Silverlight Applications and earn revenue/prizes.

Labels: , , , ,

 
posted by Abhijeet at 1:17 AM | Permalink | 0 comments