Spanish Italian
8287 Users    

SUCKERmenu

11 SMTP

Introduction
In this example, we want to use the new Microchip TCP/IP functionalities to permit to FTPMicro an e-mail to verify itself by a given event.
The proposed code, it is based principally on previous example , for which, is employed an older stack version.
In particular, we'll have a web-page through which it is possible to monitor the device temperature and modify the LED condition. At this will be added (for commodity) a new button to send the e-mails, but we'll see that will be possible to send in an automatic way.

Settings
First of all FTPMicro must be set up to be able to get to the Internet network, or rather is necessary assign an IP address and set the gateway and DNS server addresses. This operation can be effectuate modifying the relative define in the TCPIPConfig.h file
Also, it is necessary to have the access at a SMTP server, we'll see where insert its address.

The used files
There are resumed the same files used, or rather index.htm, status.cgi, style.css, style.css and ahah.js. Only the first will be (gently) modified, and at these the mail.htm files will be added that contain the the written "Mail Sent".
The code added to the main page is:

   <div class="left">
     <form>	
       <table class="status_table">
         <tr><th>Mail</th></tr>

         <tr><td><input type="submit" value="e-mail" onclick="javascript: 
noloadAHAH('/Mail.htm?m=1','maildiv','GET'); return false;" /></td></tr>
         <tr><td><div id="maildiv"> </div></td></tr>

       </table>
     </form>
   </div>

and is found before the </body> tag. With this we add a button which recall the mail.htm page with the m.
parameter.

The code
The code necessary to the software functionality is found in the MainDemo.c file and is constituted by the code already present in the example mentioned first.
The message sending is through the SMTPDemo function, that is used periodically in the main method; in this way is possible to insert directly inside of the function the event control which determines when is necessary the e-mail sending. In fact when that event will be verified, as soon as will be used this function, the control will give a hesitated positive and will start the sending practice.
This control must be inserted among these two lines:

  		case MAIL_HOME:

			break;

To begin the sending it is enough to increase with one the variable MailState. The practice will begin effectively to the next call of SMTPDemo.

One change was made happen to the method HTTPExecCmd, to intercept the parameter m:

void HTTPExecCmd(BYTE** argv, BYTE argc)
{
  	if (argv[1][0] == 't') {
		switch (argv[2][0] - '0') {
			case CMD_LED1 :
				LED1_IO = !LED1_IO;
				break;
			case CMD_LED2 :
				LED2_IO = !LED2_IO;
				break;
		}
	} else
	if (argv[1][0] == 'm')
		SMTPDemo(TRUE);
}

Compared with the official code, I added to the method SMTPDemo a parameter of booleano type, which permits to start the e-mail sending from any code point, rather to effectuate a control inside that method.

SMTPDemo
The sending of an e-mail it isn't immediately, but requires many calls of the SMTPDemo method, that's why are exploited two LED to communicate the operation condition. The first LED is turned on over the sending process, while the second, at the operation end, it is turned on if this had a good end.

To conclude, we'll see what we find inside of SMTPDemo.
- On the first part (MAIL_BEGIN), are some "configurations" string, or rather the SMTP server address, the recipient address, that of the sender and the message object.
- On the next section (MAIL_PUT_DATA), is wrote in the message text a first part of the message (purely static), and then is inserted the temperature actual value.
- At last (MAIL_SMTP_FINISHING) is concluded the operation.

AttachmentSize
FTPMicro_SMTP.rar1.49 MB

Who's new

  • chulhee
  • moliv
  • pippopippo
  • athamer
  • jayasimhan

Who's online

There are currently 0 users and 17 guests online.