Send a mail...

As a more complex example of interacting with a server, here is an example of how to send e-mail using an open relay. You can send e-mail

Select and build the project

In the examples for your board, you'll find a Networking Projects solution, and within that a Send E-mail project. Double-click that project to make it active and press F7 to build.

SMTP server

You need to configure the SMTP server for this example to work. In the example you will need to configure SMTP_SERVER with the domain name or dotted-decimal IP address of your SMTP server, and also set USER_EMAIL_ADDRESS to the e-mail address of the recipient.

The code

There is nothing new in this example, it's just a little longer than retrieving a web page in the previous example.

/* Copyright (c) 2004-2013 Rowley Associates Limited.

#include <string.h>
#include "example_support.h"
#include "libnet/ctl_net_api.h"
#include "libnet/extras/ctl_smtp_client.h"
#include "libplatform/platform.h"
#include "libplatform/platform_network.h"

// TODO: Example SMTP server address.  Replace with yours, either
// dotted-decimal or DNS name.
#define SMTP_SERVER \

// TODO: Example e-mail delivery address.  Replace with yours.

// Resolved SMTP server.
static CTL_NET_IPv4_ADDR_t smtp_server_addr;

  CTL_STATUS_t stat;
  char dot_ipaddr[16];

  // Initialize platform.

  // Start networking, wait for an IP address.

  // Wait 5s to see if we can resolve our mail server.  If you
  // use a dotted-decimal IPv4 address, there is no name lookup
  // and this completes immediately.
  printf("DNS: Resolving %s, maximum wait for DNS reply is 5 seconds.\n",
  printf("DNS: Resolved %s to %s\n",
        ctl_ip_sprint_addr(dot_ipaddr, smtp_server_addr));

  // Attempt to send some mail.
  stat = ctl_smtp_client_send_mail(smtp_server_addr,
                                   "",  // fake
                                   "Hello from the CrossWorks TCP/IP Library!",
                                   "Hello!\n\nThis is the CrossWorks TCP/IP Library"
                                     "sending an e-mail to you.\n\n"
                                     "Regards,\n\n-- The CrossWorks Team.");

  // Say whether it worked.
  if (stat < CTL_NO_ERROR)
    example_terminate("SMTP: Didn't send that e-mail correctly.  Sorry.");
    printf("SMTP: E-mail sent OK!\n");

  // Done.
  return example_finish();