Supporting software can be a pretty difficult task. Trying to visualize / recreate a specific condition that is throwing a troublesome exception might have you reaching for tums. Hey... I have an idea - just create an error reporting dialog that sends you an email with the details!
First things first... there are a whole bunch of crazy landmines we need to talk about.
- as3maillib does not support email servers that require authentication
- this is a tutorial: your implementation = your responsibility / risk
- showing the user the contents of an error report is a good idea
- giving the user the option to send / not send an error report is a good idea
- never include any private, personal, or sensitive information in an error report
- obfuscating operations / conditions via error codes is a good idea
- sending a report with every exception will have you swimming in emails (bad?)
So... with all the warning what is this good for then? Your mileage may vary depending on your application but generally:
- email is a very inexpensive alternative to formal error management infrastructures
- emailing error reports can help you navigate firewall restrictions
- the sum of your reports can give you a good idea where your application needs the most attention
- the sum of your reports can help you define urgency and priority for specific issues
Victor Welling put this library together a little while ago... so, if you are already familiar with it - cool. If you aren't, you can get the latest bits from the as3maillib repository.
The implementation is pretty basic - the following script block is all there is to it.
import org.oxcode.mail.Contact;
import org.oxcode.mail.Mail;
import org.oxcode.mail.smtp.SMTPConnector;
private var smtp:SMTPConnector;
private function openConnection():void
{
smtp = new SMTPConnector( "mail.yourdomain.com", "some_user_account" );
smtp.connect();
}
private function sendEmail():void
{
var sender:Contact = new Contact( "some_user@yourdomain.com", "Some User" );
var recipient:Contact = new Contact( "another_user@anotherdomain.com", "Another User" );
var mail:Mail = new Mail();
mail.from.push( sender );
mail.cc.push( recipient );
mail.subject = "Sending Email from Flex";
mail.plaintextContent = "Did you know you can send email from a Flex application?";
if ( smtp.state == SMTPConnector.STATE_MAIL_TRANSACTION_READY )
smtp.send( mail );
}
private function closeConnection():void
{
smtp.close();
}
My only complaint about as3maillib is that it doesn't leverage or rather re-purpose its internal connection events externally as a means to simplify the process of connecting, sending an email, and disconnecting. As it stands, you'll probably have to poll SMTP connection state before each operation. Still... a helpful piece of work.