19 April 2006

Java: sending email

Just found this simple example for sending email (via SMTP) without using any extra libraries:

//This works without any extra libraries!
//Code adapted from http://www.javaworld.com/javaworld/javatips/jw-javatip36-p3.html
//and Craig Morrall

String sender = '';
String reciever = '';
String subject = 'This message is coming from Processing';
String message = 'Mail Message';
String mailServer = 'postbox.gold.ac.uk';

//strange java thing to get a correct carriage return
String carriageReturn = System.getProperty('line.separator');

void setup()
{
sendMessage();
}

void sendMessage()
{
println('Trying...');
try {

//connect to the mail server
Socket socket = new Socket(mailServer, 25);

//create an in and out connection
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
DataInputStream in = new DataInputStream(socket.getInputStream());

//ask your machine what it's really called
String hostname = InetAddress.getLocalHost().getHostName();
println('HOST: '+hostname);

//converse with the mail server
readIn(in);
sendEmail(out, in, 'HELO ' + hostname + carriageReturn);
readIn(in);
sendEmail(out, in, 'RSET' + carriageReturn);
readIn(in);
//tell the mail server your email
sendEmail(out, in, 'MAIL FROM: ' + sender + carriageReturn);
readIn(in);
//tell the mail server where you want to send the message
sendEmail(out, in, 'RCPT TO: ' + reciever + carriageReturn);
readIn(in);
//start the message body
sendEmail(out, in, 'DATA' + carriageReturn);
readIn(in);
sendEmail(out, in, 'To:' + reciever + carriageReturn);
sendEmail(out, in, 'From:' + sender + carriageReturn);
sendEmail(out, in, 'Subject: ' + subject + carriageReturn);
sendEmail(out, in, message);

//close the message body
sendEmail(out, in, carriageReturn + "." + carriageReturn);
//end of message body

//end the conversation
readIn(in);
sendEmail(out, in, "QUIT" + carriageReturn);
readIn(in);

//close the connections
in.close();
out.close();

println("Message '" + subject + "' sent to '" + reciever + "'");

}//end of try statement
catch (UnknownHostException e)
{
println("Unknown Host Exception: " + e);
}//end of catch statement
catch(IOException e)
{
println("Send failure: " + e);
}//end of catch statement

}//end of method sendMessage

void sendEmail(DataOutputStream out, DataInputStream in, String stringHolder)
throws IOException
{

if(stringHolder != null)
{
out.writeBytes(stringHolder);
println(stringHolder);
}//end of if statement

}//end of method sendEmail

void readIn(DataInputStream in)
throws IOException
{
String record;

if ((record = in.readLine()) != null)
{
println("Message from host: "+record);
}//end of if statement

}//end of method readIn

07 April 2006

Nifty Corners in CSS

Check out these awesome samples of round corners in web pages without using images - all with a little CSS, some Javascript and vanilla HTML: Nifty Corners Cube

While I'm thinking about it, here are some arguments for CSS-type layouts (with no tables or any of that other cruft):
... which reminds me - here's an essential extension for Firefox: WebDeveloper. WebDeveloper has loads of useful features, including the ability to edit the CSS styling of a page on the fly (great for changing colours, sizes etc until it's exactly how you want it).

Creating accessible websites

Not many organisations realise that the UK's Disability Discrimination Act (DDA) now extends to websites - it will probably take a few high profile legal actions before anyone really takes notice. However, regardless of the legality of it, the practices that make your website more accessible to the visually impaired will also make it more accessible for everyone else.

So, how to do it? A good place to start is Mark Pilgrim's fantastic step-by-step guide at http://diveintoaccessibility.org/ (browse online or download a PDF). There's highly readable info on doc types, alt tags (all the stuff you'd expect), but also on the need to have an accessibility statement, and support for Access Keys (a completely new area for me - ironic considering my love of keyboard shortcuts!) - most browsers support keybard shortcuts to access specific pages (or anchors); on Windows, you can press ALT + an access key; on Macintosh, you can press Control + an access key.

05 April 2006

Great UIs: simple once you’ve seen that they’re possible

I've just bought the 'beta' PDFs of two new Pragmatic Programmer titles: 'Pragmatic AJAX' and 'Rails Recipes' (because they're in beta, they're not available as hard copy yet, and I'll get updates as the title develops - nice idea). In the AJAX book, chapter 1 (in describing Google Maps, which arguably kickstarted the current AJAX / Web2.0 boom) has a quote from Glenn Vanderburg that I want to remember for my forthcoming presentation on Web20: "Technically it’s easy, but the conception of this kind of interface is the really amazing part, just having the idea and then realizing that it could be done. So many things are simple once you’ve seen that they’re possible."

04 April 2006

The Open Ajax Initiative

From Zimbra (Press Release, Feb 1st 2006): "Tech Titans Contribute Browser-Boosting AJAX Technologies to Open Source Community"

Prominent high-tech businesses (BEA, Borland, the Dojo Foundation, Eclipse Foundation, Google, IBM, Laszlo Systems, Mozilla Corporation, Novell, Openwave Systems, Oracle, Red Hat, Yahoo, Zend and Zimbra) announced that they are making it easier for an open-source community to form and popularize Ajax (Asynchronous JavaScript And XML). Ajax is a fast-growing open client technology that is being incorporated into Web sites to simplify the browsing experience (and reduce page load times), making it easier for users to collaborate, work, play, shop, correspond and navigate online.

03 April 2006

Exporting Thunderbird contacts to GoogleMail

I've just bought a copy of 'Getting Real', the PDF eBook self-published by 37signals (those purveyors of Web2.0 goodness). They send you a download link which is only valid for a day or so, and they recommend you keep a back up - this made me panic a bit, so I emailed my PDF to my googlemail account. A nice freebie with this approach to backing up (i.e. storing it in your Gmail account) is that PDFs are viewable as HTML as well. It also put up some AdWords to AJAX tutorials - smart.

Anyway, while I was refreshing myself with GoogleMail, I thought I'd upload my contacts from Thunderbird. Thunderbird provides an Export to CSV option, but it comes out without a header line; the GoogleMail contacts CSV import feature requires a header. So, here's my best shot - paste it in as the first line of your CSV file:

First Name,Last Name,Display,Nickname,Email,Additional Email,Work Tel,Home Tel,Fax,Pager,Mobile,Home Address 1,Home Address 2,Home City,Home County,Home Post Code,Home Country,Work Address 1,Work Address 2,Work City,Work County,Work Post Code,Work Country,Work Title,Department,Organisation,Work Web Page,Home Web Page,unknown 1,unknown 2,unknown 3,Custom 1,Custom 2,Custom 3,Custom 4,Notes,unknown 4

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]