Go Down

Topic: How to access smtp.gmail.com or other to send email (Read 11 times) previous topic - next topic

koklimabc

Oct 12, 2012, 10:52 am Last Edit: Oct 12, 2012, 10:54 am by koklimabc Reason: 1
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( ;; )
    ;
  }
}

SurferTim

#1
Oct 12, 2012, 01:41 pm Last Edit: Oct 12, 2012, 01:57 pm by SurferTim Reason: 1
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.

koklimabc

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?

SurferTim

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.


sbright33

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

Skype Brighteyes3333
(262) 696-9619

Go Up