LAZIOMATICA – Guida allo Sviluppo Software

La nuova forma del software su misura…

 

ASMailer – Send Email in AS 3 without server-side script

The ASMailer class sends emails using an SMTP server. ASMailer sends mail without the need of a server side language like PHP or JSP.
The ASMailer class sends emails using an SMTP server. ASMailer sends mail without the need of a server side language like PHP or JSP. This project is in alpha state. Currently sends using SMTP servers that do not require authentication or SSL connection. Currently only test on default port 25.

Usage:

import com.almerblank.fl.net.mail.Email;
import com.almerblank.fl.net.mail.ASMailer;
import com.almerblank.fl.net.mail.events.MailEvent;
import com.almerblank.fl.net.mail.events.MailErrorEvent;

private var mail:ASMailer;

private function init():void
{
mail = new ASMailer( ‘mail.yourserver.com’ );
mail.addEventListener( MailEvent.SMTP_CONNECTION_READY, _connReady );
mail.addEventListener( MailEvent.SMTP_STATUS_EVENT, _handleStatus );
mail.addEventListener( MailEvent.SMTP_EMAILING_COMPLETE, _emailsComplete );
mail.addEventListener( MailEvent.SMTP_DISCONNECTED, _disconn );
mail.addEventListener( MailErrorEvent.SMTP_SERVER_ERROR, _smtpErrorHandler );
mail.addEventListener( MailErrorEvent.SMTP_IOERROR, _smtpIOError );
mail.addEventListener( MailErrorEvent.SMTP_SECURITY_ERROR, _smtpSecError );
}

private function _disconn( event:MailEvent ):void
{
trace( ‘disconnected…’ );
}

private function _emailsComplete( event:MailEvent ):void
{
trace( ‘_emailsComplete()’ );
}

private function _smtpIOError( event:MailErrorEvent ):void
{
trace( ‘event.message = ‘ + event.message );
}

private function _smtpSecError( event:MailErrorEvent ):void
{
trace( ‘event.message = ‘ + event.message );
}

private function _handleStatus( event:MailEvent ):void
{
tf_status.text += event.status;
tf_status.text += ‘\n’;
tf_status.verticalScrollPosition = tf_status.maxVerticalScrollPosition;
}

private function _smtpErrorHandler( event:MailErrorEvent ):void
{
trace( ‘event.code = ‘ + event.code );
trace( ‘event.message = ‘ + event.message );
trace( ‘event.failedOnCommand = ‘ + event.failedOnCommand );
}

private function _connReady( event:MailEvent ):void
{
sendEmails()
}

private function sendEmails():void
{
var lipsum1:String = ‘…text…’;
var lipsum2:String = ‘…text…’;

// one email send to one person
var em:Email = new Email( ‘user@laziomatica.com’, [ 'toUser@laziomatica.com' ], ‘message 1 subject’, lipsum1 );

// one email to two people
var em2:Email = new Email( ‘user@laziomatica.com’, [ 'toUser@laziomatica.com', 'toSecondUser@3life.it' ], ‘message 2 subject’, lipsum2 );

// send multiple in an array
mail.sendMail( [ em, em2 ] );

// send one in an array
//mail.sendMail( [ em ] );

}

This code should work in Flash and Flex. The init() method would start the process.

Another MXML Mailer Application:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute” creationComplete=”init()”>
<mx:Script>
<![CDATA[

import com.almerblank.fl.net.mail.Email;
import com.almerblank.fl.net.mail.ASMailer;
import com.almerblank.fl.net.mail.events.MailEvent;
import com.almerblank.fl.net.mail.events.MailErrorEvent;

private var mail:ASMailer;

private function init():void
{
mail = new ASMailer( '10.109.70.11' );
mail.addEventListener( MailEvent.SMTP_CONNECTION_READY, _connReady );
mail.addEventListener( MailEvent.SMTP_STATUS_EVENT, _handleStatus );
mail.addEventListener( MailEvent.SMTP_EMAILING_COMPLETE, _emailsComplete );
mail.addEventListener( MailEvent.SMTP_DISCONNECTED, _disconn );
mail.addEventListener( MailErrorEvent.SMTP_SERVER_ERROR, _smtpErrorHandler );
mail.addEventListener( MailErrorEvent.SMTP_IOERROR, _smtpIOError );
mail.addEventListener( MailErrorEvent.SMTP_SECURITY_ERROR, _smtpSecError );
}

private function _disconn( event:MailEvent ):void
{
trace( 'disconnected...' );
}

private function _emailsComplete( event:MailEvent ):void
{
trace( '_emailsComplete()' );
}

private function _smtpIOError( event:MailErrorEvent ):void
{
trace( 'event.message = ' + event.message );
}

private function _smtpSecError( event:MailErrorEvent ):void
{
trace( 'event.message = ' + event.message );
}

private function _handleStatus( event:MailEvent ):void
{
tf_status.text += event.status;
tf_status.text += '\n';
tf_status.verticalScrollPosition = tf_status.maxVerticalScrollPosition;
}

private function _smtpErrorHandler( event:MailErrorEvent ):void
{
trace( 'event.code = ' + event.code );
trace( 'event.message = ' + event.message );
trace( 'event.failedOnCommand = ' + event.failedOnCommand );
}

private function _connReady( event:MailEvent ):void
{
sendEmails()
}

private function sendEmails():void
{
var lipsum1:String = '...text...';
var lipsum2:String = '...text...';

// one email send to one person
var em:Email = new Email( 'laziomatica@gmail.com', [ 'ideasviluppo@gmail.com' ], ‘message 1 subject’, lipsum1 );

// one email to two people
var em2:Email = new Email( ‘cert@laziomatica.com’, [ 'ideasviluppo@gmail.com', 'info@3life.it' ], ‘message 2 subject’, lipsum2 );

// send multiple in an array
mail.sendMail( [ em, em2 ] );

// send one in an array
//mail.sendMail( [ em ] );

}
]]>
</mx:Script>
<mx:TextArea x=”0″ y=”0″ width=”309″ height=”289″ id=”tf_status”/>

</mx:WindowedApplication>

Filed under : Senza categoria
By admin
On 12 gennaio 2009
At 20:36
Comments :Commenti disabilitati
 
 

AIR mx:HTML open a web link into _blank page

When I decided to write an application like a browser to use like a container for a web apllication writed in PHP, i thinked to use mx:HTML component of Flex Framework, but in this component i f i try to open an html link i have a not opening issue. The issue was if I am rendering html which is having <a href…> tag with target=”_blank” attribute then AIR doesn’t respond or open these links in new browser window, however if I have <a href…> tag without target=”_blank” attribute then HTML control will load these links in same window inside AIR application.

Searching online for a solution i found an alternative mode to solve it by manipulating DOM elements after loaded html and getting list of <a href…> tags and overriding their “onmouseup” event and assigning it to Actionscript function which opens link in new browser window using navigateToURL() method call. This is one of the powerful functionality of mx:HTML control that it allows you to manipulate DOM elements without any restrictions. But thing to remember is that you cannot manipulate DOM elements until page is loaded completely that is the reason I am using “complete” event of mx:HTML to do manipulation.

Filed under : AIR,RIA
By admin
On
At 17:56
Comments : 0