Pages: [1]   Go Down
Author Topic: Help me understand this send mail code! Thank you!  (Read 769 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7198
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
// 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!
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6038
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Quote
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.  smiley-sad

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!).
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7198
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6038
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-lol

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.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7198
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9636
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-eek-blue
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6038
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-eek-blue
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.
« Last Edit: April 19, 2013, 06:53:33 am by SurferTim » Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9636
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

Code:
   for(;;)
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7198
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 147
Posts: 6038
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: