Go Down

Topic: WiFi101 e-mail with attachment using a Mega: Fully Working Code (Read 1 time) previous topic - next topic


I got the new WiFi101 board a week ago.
It worked straight out of the box, plugged into a Mega 2560.

So far I have written a web server and a SMTP e- mail sender.

For e-mail, I started with the code written by Razorblade

It worked but was very slow because of the utilisation of a single byte read , single byte write method.
No doubt this allows a Uno, with limited memory, to complete the task.

The mega has enough memory to create a read and write buffer.
I was able to use Razorblade's encodeblock to convert each group of 3 bytes to 4 base 64 bytes.
The buffering decreases the encode time from 43 seconds to 0.5 seconds on a small jpeg.

Time and date was obtained by adapting the example code in  WiFiUdpNtpClient.ino
I have included Base 64 encoding for the login to Plain authorised ESMTP servers.

The code is too big to post, but I have attached it.

Full details are shown in the comments:
Code: [Select]


Send an email from WiFi101 using an Arduino Mega 2560
Authentication option
  Routine to generate base 64 authentication login
With / without attachment
  Fast Base 64 encoding of attachment to temp file (37.56 KB in 1.040 S)
  Fast block write of encoded attachment file
    (6.34 S to complete e-mail with 37.56 KB attachment)
    (4.40 S to complete without an attachment)
Include ntp time & date from ntp server
Options for high priority and read receipt (outlook parameters)
Serial output can be disabled
Status led, with error indication

Use wifi button to send e-mail
  - see void sendit for e-mail addresses, pictures and subjects

D.R.Patterson 8/2/2016

Achnowledgement for base64 encoding

Attach an led with 1Kohm serial resistor between pin 12 and 0
This led indicates status:

  On for one second - setup complete, ready to e-mail.
    Mail is sent by pressing the WiFi101 button
  2hz continual flash - a hardware error has occured
  2  x 2hz flashes e - encoding failed
  4  x 2hz flashes e - Can not connect to mail server
  6  x 2hz flashes e - Authentication type rejected
  8  x 2hz flashes e - Authentication details rejected
  10 x 2Hz flashes sender address rejected
  12 x 2Hz flashes receiver address rejected
  LED On Sending e-mail:
    Alternating beteen high/low state quickly- encoding - a block has been processed

Getting started:
  Alter useserial as required.
  Some filing, mailing and Wifi parameters require editing.
  Fill in the e-mail details in void sendit:
    Sender, recipient, attachment, subject, body message, priority and read request.
  (Copy the required attachment files to the Arduino sdcard.)
  Attach led with 1K series resitor- anode to pin 12, Cathode to 0V.


Go Up