OUI

The Wireless FAQ

7.6 How can I send e-mail from a WAP device?

In the HTML world, there's a simple way to trigger the default e-mail editor. At present there is no such thing in WML, and e-mails must be entered through a WML form.

has released a completely brilliant POP client for WAP devices under GPL, called WAPpop, and this is available for download at SANIsoft's site. WAPpop uses PHP and mySQL, which both come preinstalled on most Linux distributions.

If you need to build another type of user interface around the mail function, a typical email form would look something like this:

<wml>
  <card id="edit" title="Email Editor">
    <p>From: <input type="text" name="from" format="*M"/></p>
    <p>To: <input type="text" name="to" format="*M"/></p>
    <p>Subject: <input type="text" name="subject" format="*M"/></p>
    <p>Message body: <input type="text" name="body" format="*M"/></p>
    <p>
      <anchor>Send this mail
        <go method="post" href="http://some.host/mailhandler"?action=send/">
          <postfield name="from" value="$(from)"/>
          <postfield name="to" value="$(to)"/>
          <postfield name="subject" value="$(subject)"/>
          <postfield name="body" value="$(body)"/>
        </go>
     </anchor>
    </p>
  </card>
</wml>

In the code above you'll notice the reference. This is a CGI, a server side script of some sort that will handle the input from the mail form and transform it into an e-mail message and send it. There are virtually thousands of such scripts available in all sorts of script languages.

If you plan to use a similar form for sending mail, you will most likely have to edit the variable names. Also note that there's a limit to the amount of data that can be sent from your WAP device to the server. Long messages will most likely break.

To demonstrate how it works, the following PHP script could be used to handle mail from the form. It will format a WML deck with a card that tells the user if the mail was sent or not. For real life applications, you should add checks for things like well formatted e-mail addresses etc.

<?
  header("Content-type: text/vnd.wap.wml");                  // Tell the client that this is a WML deck
  echo("<?xml version=\"1.0\"?>\n");
  echo("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://....\">\n");
  $mailer = "wap.colorline.no";                              // The name of your mail server
  $from = $from." (WAP user at ".$mailer.")";                // Format the from field
                                                             // Add the from field and some
                                                             // character handling to the extra headers
  $extraheaders = $from."\nContent-Type: text/plain; charset=iso-8859-1\nContent-Transfer-Encoding: 8bit";
  echo("<wml>\n");                                           // Start sending out the WML deck
  if(mail($to,$subject,$body,$extraheaders)) {               // Use PHP's internal mail functionality
    echo("<card id=\"sent\" title=\"Mail sent\">\n");        // Mail was successfully sent
    echo("<p>Mail was sent successfully</p>\n");
    echo("</card>\n");
  }
  else {
    echo("<card id=\"notsent\" title=\"Mail failed\">\n");   // The mail could not be sent
    echo("<p>Unable to send mail</p>\n");
    echo("</card>\n");
  }
  echo("</wml>\n");
?>

For security reasons the code above does not have a demo on this server. You should also consider this. The code above gives basically anyone access to send e-mails to anyone - anonymously.

[ Main ]   [ 07 - Making it look fancy ]