How to send an Email with Arduino and Ethernet Shield (W5100)

From MCS Wiki
Revision as of 12:58, 10 March 2013 by MAK3 (Talk | contribs)
Jump to: navigation, search


Used Hardware

  • Arduino UNO R3
  • Ethernet Shield with W5100 Wiznet Chip  

Used Software


Windows7 or 8

What you need to run the example

For the following example you need:

  • Email account which supportSMTP Authentication (AUTH LOGIN) on Port 25
  • Username and password Base64 encoded (you can use the Easy TCP/IP tool in Bascom-AVR to encode and decode)
  • IP address of your smtp server (if you do not know it just open in Windows the DOS command window and ping the server)
  • Your sender Email address and the receiver Email address

Don't use the Email Sub in the Do...Loop until you know what you are doing (Your mail provider could ban you if you send too much emails) !

Telnet Exercise with sending an Email (if you encounter a problem)

The AUTH LOGIN smtp command is used to login to the smtp server with Username and password (both must be sent Base64 encoded).

You can use the Easy TCP/IP Tool in Bascom-AVR to decode or encode Base64.

You can check all the single steps of the SMTP server communication with TELNET in a manual procedure:

1. Enabling Telnet Client in Windows 7
2. Start the DOS command window in Windows 7 and type telnet and return
3. Then you see:         Microsoft Telnet>         in the DOS command window.
4. Now type (we use as example GMX with Port 25):             open 25             (25 is the port number)
5. The answer from the SMTP server will be: 220 GMX Mailservices ESMTP {mpXXX}
6. Then type:         AUTH LOGIN
7. The answer from the SMTP server will be: 334 VXNlcm5hbWU6
8. If you decode the   VXNlcm5hbWU6   for example with the Easy TCP/IP Tool in Bascom-AVR
    you will notice that the decoded text is Username:
9. You need now to type in the username Base64 encoded (which is usually your Email address Base64 encoded)
10. After this the SMTP server ask for the password (also Base64 encoded)
11. If you type in the wrong username or password the server's answer is 535 5.7.0 Incorrect username or password {mpXXX}
12. The correct username and password will be answerd by:   235 2.7.0 Go ahead {mpXXX}
13. ...
14. You can start the Email content with DATA and end it with <CR><LF>.<CR><LF> which is in Bascom {013}{010}.{013}{010}

Under Construction


SMTP Server Reply Codes

Code Description

211 System status, or system help reply.
214 Help message.
220 Domain service ready.Ready to start TLS.
221 Domain service closing transmission channel.
250 Ok , Queuing For Node Node Started.requested Mail Action Okay , Completed.
251 Ok , No Messages Waiting For Node Node.user Not Local , Will Forward To Forwardpath.
252 OK, pending messages for node node started.Cannot VRFY user (e.g., info is not local), but will take message for this user and attempt delivery.
253 OK, messages pending messages for node node started.
354 Start mail input; end with <CRLF>.<CRLF>.
355 Octet-offset is the transaction offset.
421 Domain Service Not Available , Closing Transmission Channel.
432 A password transition is needed.
450 Requested mail action not taken: mailbox unavailable.ATRN request refused.
451 Requested action aborted: local error in processing.Unable to process ATRN request now
452 Requested action not taken: insufficient system storage.
453 You have no mail.
454 TLS not available due to temporary reason.Encryption required for requested authentication mechanism.
458 Unable to queue messages for node node.
459 Node node not allowed: reason.
500 Command not recognized: command.Syntax error.
501 Syntax error, no parameters allowed.
502 Command not implemented.
503 Bad sequence of commands.
504 Command parameter not implemented.
521 Machine does not accept mail.
530 Must issue a STARTTLS command first.Encryption required for requested authentication mechanism.
534 Authentication mechanism is too weak.
538 Encryption required for requested authentication mechanism.
550 Requested action not taken: mailbox unavailable.
551 User not local; please try forwardpath.
552 Requested mail action aborted: exceeded storage allocation.
553 Requested action not taken: mailbox name not allowed.
554 Transaction failed.

Under Construction


Personal tools