Help me understand this send mail code! Thank you!

I am learning the basics of networking, sending an email. I got a link from SurferTim for the following code on the playground:

http://playground.arduino.cc/Code/WiFiEmailClient

Here is the code that sends the mail:

// change to your email address (sender)
   client.write("MAIL From: <me@mine.com>\r\n");

  if(!eRcv()) return 0;

// change to recipient address
   Serial.println("Sending To");
   client.write("RCPT To: <you@mine.com>\r\n");

  if(!eRcv()) return 0;

  Serial.println("Sending DATA");
   client.write("DATA\r\n");

  if(!eRcv()) return 0;

  Serial.println("Sending email");

// change to recipient address
   client.write("To: You <you@mine.com>\r\n");

// change to your address
   client.write("From: Me <me@mine.com>\r\n");

I wonder why sender and recipient addresses are sent twice. Does the second time just show up as email content?
So if I replace the sender email with say another person's email address, say Mr. X, will the recipient think that the email came from Mr. X? Kind of dangerous?!
Where is the user logon part that we all do before we can send an email? I'm confused.
What is "helo"?

Thank you!

I wonder why sender and recipient addresses are sent twice. Does the second time just show up as email content?

The first time it is sent, it is for the benefit of the email server. The second time is for the email "From" in your email message. Note it contains your name, so it shows from "Me" in the From field.

So if I replace the sender email with say another person's email address, say Mr. X, will the recipient think that the email came from Mr. X? Kind of dangerous?!

Not dangerous unless you are easily fooled. Spammers use this all the time. I get spam mail from me. :frowning:

helo is email server for Hello.

There is no login. No user. No password. This does not send email like an email client. This sends email like an email server (or a spammer!).

Thank you SurferTim!

So does this mean essentially the Arduino is only sending out emails (using any email address it wants) to this server but is not reachable via email since no routers know where to deliver mail to some phoney email address? What if the recipient address is not reachable or inbox is full? Will the server respond with a message that will be printed by eRcv()?

Now I am understanding that theft of email addresses/contacts is serious since someone can pretend to be the person of that email address and provide phishing links in the email and I would think it's from a friend of mine.

Oh, it gets better than that! Like I said, I get spam mail from me. It is my name and email address as the sender, and the same for the recipient. If you reply to it, you get the reply in your email. XD

The server will respond with the appropriate codes. If the mailbox is full or non-existent, you should get a response code of 400 or bigger. That is why the code checks the first character of the response for every send. If it is 4 or larger, it is a fail. 3 or smaller is a pass.

Thank you SurferTim. That was eye opener for me! I'll get started with some spamming once I get home.

Be careful while testing. With email code loaded in the arduino, mail will be sent every time you reboot the arduino opening the serial monitor and such. You can email bomb your own mail box if not careful. :fearful:

zoomkat:
Be careful while testing. With email code loaded in the arduino, mail will be sent every time you reboot the arduino opening the serial monitor and such. You can email bomb your own mail box if not careful. :fearful:

My code won't. It requires the 'e' key press (or some other trigger) to send email.

edit: I did not notice the email client code in the playground had no timeouts if the connection failed, so I added timeouts to both the ethernet and wifi email code today.

My code won't. It requires the 'e' key press (or some other trigger) to send email.

Mine also uses an e to send, but some early posted code was made to send an email when the serial monitor was opened and used the below to stop the loop. It was an early lesson in that any internet communication code needs to be made somewhat "spew" proof, or one might get a supprise.

   for(;;)

So I wonder whether there are servers that can accept emails from DHCP clients. Is there a list, such as yahoo, outlook, attwireless? Thanks. I have not got time to try yet.

You may be able to send now. I would try first. If you need a smtp service, I hear this is ok.