E-mail (SMTP) Demo

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
E-mail (SMTP) Demo

Overview 

This file provides two examples for using the SMTP client module to send e-mail messages. The first transmits short alert messages whose entire bodies can be stored in RAM at once. The second example demonstrates how to generate messages on-the-fly when the entire body cannot be allocated in RAM. (This second example is commented. You must comment the first example and uncomment this one to use it.) 

A third example of using the SMTP client is provided in HTTPPostEmail. This example shows how to send messages with attachments, as well as how to dynamically configure the recipient and e-mail server at run-time. 

Instructions (Short Message Demo) 

  1. Open your project in MPLAB and open SMTPDemo.c. Scroll down to the MAIL_BEGIN case in the switch statement in the SMTPDemo() function.
    1. Replace the initializer of the RAMStringTo[] array with the target email address.
    2. Replace the initializer of the SMTPClient.Server.szROM structure element with the address of your mail server. Note that this demo does not include security features, so you will need a mail server that does not require SSL. To test this functionality with a mail server that does support SSL (including most public mail servers), please use the HTTPPostEmail SMTP demo.
  2. Compile the code, program your board, and run the demo.
  3. Press buttons 2 and 3 on your board to transmit an email message. LED1 on your board will indicate that the message is being transmitted; LED2 will indicate that is was sent successfully. Check the BUTTON2_IO, BUTTON3_IO, LED1_IO, and LED2_IO macros in the copy of HardwareProfile.h that corresponds to your project to determine which buttons and LEDs are used for your hardware setup.
  4. Verify that the message was received by the email account you specified in the RAMStringTo[] array.

Description 

The short-message SMTPDemo task function implements a four-state state machine. When the board is powered on, the state machine is initialized to the SM_HOME state, in which it waits for buttons 2 and 3 to be pressed. Once they are pressed, the task will enter the MAIL_BEGIN state. 

In the MAIL_BEGIN state, the task will attempt to requisition the SMTP module. Once it's able to do this, it will populate the SMTPClient structure with message parameters and transmit the message. It will then enter the MAIL_SMTP_FINISHING state. 

In the MAIL_SMTP_FINISHING state, the task will check a callback function (SMTPIsBusy) to determine when the module is finished. It will then give up control of the SMTP module and toggle LEDs based on the successful operation of the SMTP module. The state machine will then enter the MAIL_DONE state, which will wait at least 1 second before transitioning back to MAIL_HOME, allowing another email to be sent.

Functions
 
Name 
Description 
 
Demonstrates use of the e-mail (SMTP) client. 
Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.