Sending Mail from Processing

Here’s a piece of code to send mail from Processing. It uses the net library. Warning: your mail server may not use port 25.

/* mail_client
 by Tom Igoe
 
  A simple mail sender client
 Created 21 January 2006
 */

import processing.net.*; 
Client myClient; 
int clicks;
String reply = null;
boolean sent = false;
void setup() { 
  // Connect:
  myClient = new Client(this, "echonyc.com", 25); 
  delay(300);

} 


void draw() { 
  if(!sent) {
    waitForReply();
    myClient.write("HELO echonyc.com\n");
    waitForReply();
    myClient.write("MAIL FROM:tigoe@echonyc.com\n");
    waitForReply();
    myClient.write("RCPT TO:tigoe@echonyc.com\n");
    waitForReply();
    myClient.write("DATA\n");
    waitForReply();
    myClient.write("Subject:Noodles\n");
    myClient.write("From:tigoe@echonyc.com\n");
    myClient.write("To:tigoe@tigoe.net\n");
    myClient.write("\rHere's the body\n.\n");
    waitForReply();
    myClient.write("QUIT\n\r");
    waitForReply();
  }
  sent = true;
} 


void waitForReply() {
  int newChar = 0;
  while (newChar != 10) {
    if(myClient.available() > 0) {
      newChar = myClient.read();
      reply += (char)newChar;
    }
  }
  println(reply); 
}