Pages: [1]   Go Down
Author Topic: How to access smtp.gmail.com or other to send email  (Read 9761 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can anyone help me on how to access to gmail smtp server and make changes to the following. Appreciate thanks to any suggestion and help.

I've tried my following setup code without any problem to send out email automatically to my gmail mailbox under my local smtp domain server.

My main purpose would liked to use public smtp server for sending out email but not involved local setup smtp mail's server because I'll create a device which is not rely on local setup email server but connect solely direct to Internet for automatically send out email by interact to public smtp server only.



#include <Ethernet.h>

#include <SPI.h>  

//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//byte ip[] = { 192, 168, 9, 177 };
//byte server[] = { 192, 168, 9, 6 }; // Mail server address  MODIFY THIS FOR THE TARGET DOMAIN's MAIL SERVER

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 9, 177 }; // ip in lan
byte gateway[] = { 192, 168, 9, 3 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte smtp[] = { 192,168,9,6 };

EthernetClient client;
//EthernetServer server(25);
//Client client(server, 25);
//Client client;
void setup()
{
  Ethernet.begin(mac, ip,gateway,subnet);
  //server.begin();
  Serial.begin(9600);
  
  delay(1000);
  
  Serial.println("connecting...");
  
 // EthernetClient client = server.available();
  
  if (client.connect(smtp,25)) {
    Serial.println("connected");
    client.println("EHLO kltan");
    client.println("AUTH LOGIN");                         //see "http://base64-encoder-online.waraxe.us/"
    client.println("a2x0YW5AcHBoLmNvbS5teQ==");           //Type kltan@pph.com.my and encode it
    client.println("MTIzNDU2");                                                      //This line is password
    client.println("MAIL FROM:<someone@hotmail.com>");  
    client.println("RCPT TO:<someone@gmail.com>");
    client.println("DATA");
    client.println("from:someone@hotmail.com");
    client.println("to:someone@gmail.com");
    client.println("SUBJECT: Testing subject to arduino ethernet shield");
    client.println();
    client.println("This is the line body.");
    client.println("This is another line of the body.");
    client.println(".");
    client.println(".");
    client.println("QUIT");
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  ;;
    if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    for( ;; )
     ;
   }
}
« Last Edit: October 12, 2012, 03:54:08 am by koklimabc » Logged

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

This link has the code I use.
http://arduino.cc/forum/index.php/topic,104449.msg784053.html#msg784053

It reads and displays the email server response after each send so you will know if it is working, and why if not.

edit: If you do not have a commercial account with a static ip, you may be blocked by the gmail server.
« Last Edit: October 12, 2012, 06:57:22 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've already tried your previous post coding test, but it still happened to have the same problem where I can't pass through STARTTLS.
How can i do to pass over STARTTLS?
Logged

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

The ethernet library does not support TLS. You can't send a user and password.

If you are using port 25, it should not want to start TLS. It does not need a user/password. Gmail is a bit picky about the sender ip range. Try using nslookup to resolve the correct server ip for your area.

Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use this instead of Gmail, it's Free:
http://www.smtp2go.com/
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Munich
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much! The following steps got me sending emails via my arduino and a wifly ethernet shield when the washing machine has finished:
register on http://www.smtp2go.com/
get the encoded version of your username and password from http://base64-encoder-online.waraxe.us/ or any other base64 encoder you prefer.
Then alter the web client example to send an email as shown above.

regards

Thomas
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's what I did too, works perfectly every time.
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


hi , I am testing your propose but when you try from cmd command ( telnet port 2525 ) with an account smtp2go do not works.

thanks for your comments
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


hi , I am testing your propose but when you try from cmd command ( telnet port 2525 ) with an account smtp2go do not works.

thanks for your comments

sounds like a replay of the below:

http://arduino.cc/forum/index.php/topic,134420.msg1010872.html#msg1010872
Logged

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

Offline Offline
Full Member
***
Karma: 0
Posts: 122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I followed your advice , I have an email account in smtp2go and this is my code but it do not works even not connects. I tested with cmd command from my pc with my smtp2go account and I had not a problem but with arduino does no connect.

thanks for your comments and sorry my english is not good.

Code:
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
#include <SPI.h>

byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x5C, 0x16};
IPAddress ip(192,168,1,5);
byte gateway  [] = {192,168,1,1};
byte subnet   [] = {255, 255, 255, 0};
byte smtp[] = {186,47,174,186};//{ 207,58,147,66 }; // I tried with two ip
EthernetServer server(80);                          //nslookup to smtpcorp.com

//IPAddress server(207,58,147,66); // conflicting declaration 'IPAddress server' -- and I do not why.
EthernetClient client;

void setup()
{
  Ethernet.begin(mac, ip,gateway,subnet);
  Serial.begin(9600);
  delay(1000);
  Serial.println("connecting...");
  if (client.connect(smtp,8025)) //2525/25/8025/587/465/8465 // I tried with all ports
  {
    delay(500);
    client.println("ehlo");
    delay(500);
    client.println("auth login");     
    delay(500);
    client.println(" name account base 64");  //mail account with smtp2go         
    delay(500);
    client.println("password base 64");
    delay(500);   
    client.println("mail from: mail account with gmail");  //This is related to smtp2go
    delay(500);
    client.println("rcpt to: xxxxxxxxxx");
    delay(500);
    client.println("data");
    delay(500);
    client.println("To: xxxxx");
    delay(500);
    client.println("From: xxxxx");
    delay(500);
    client.println("Subject: MENSAJE DE PRUEBA");
    delay(500);
    client.println();
    delay(500);
    client.println("ESTE ES UN MENSAJE DE PRUEBA DESDE ARDUINO");
    delay(500);
    client.println(".");
    delay(500);
    client.println("quit");
  }
  else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
    }
  }
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    while(true);
  }
}


Logged

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

I will point out one the first of many problems with this code. This is incorrect.
Code:
  Ethernet.begin(mac, ip,gateway,subnet);
http://arduino.cc/en/Reference/EthernetBegin

Of course, you won't know why the rest fails. You are not reading the response from the email server. I posted a link to the code I use a few posts ago.
Logged

Pages: [1]   Go Up
Jump to: