I've done this using other Wifi modules but not on the ESP8266 yet.
As long as you connect to your ISP's outbound mail server, there should be no problems in sending email.
I'm not sure if its much use, but this is the code I wrote to send email from a Arduino to a UART based wifi module
You can probably work out the flow...
Code: Select allint UARTWifi::sendEmail(char *toAddress,char *fromAddress,char *toFriendlyName,char *subject,char *message,char *loginDomain,char *mailServer)
{
char dataBuf[256];
int theSocket;
int responseCode = socketCreate("0","0",mailServer,"25",&theSocket);// 0=client,0=tcp,mailserver,port 25 for smtp, var into which the socket num is returned
if (responseCode==0)
{
#if DEBUG_LEVEL > 2
Serial.print(F("Socket created was "));//Serial.println(theSocket);
#endif
delay(250);
socketReceive(dataBuf,sizeof(dataBuf),theSocket);
//Serial.print(F("socketReceive got "));//Serial.println(dataBuf);
if (strncmp(dataBuf,"220",3)==0)
{
//Serial.println(F("Connection to SMTP server OK"));
strcpy(dataBuf,"HELO ");
strcat(dataBuf,loginDomain);
strcat(dataBuf,"\r\n");
socketSend(dataBuf,strlen(dataBuf),theSocket);
//Serial.println("waiting for 250 message");
while (socketReceive(dataBuf,sizeof(dataBuf),theSocket)==0)
{
//Serial.println(F("No data yet;-)"));
delay(SOCKET_RECEIVE_RETRY_TIME);
}
//Serial.print("Response was ");//Serial.println(dataBuf);
if (strncmp_P(dataBuf,PSTR("250"),3)==0)
{
//Serial.println("HELO message was OK");
strcpy_P(dataBuf,PSTR("MAIL FROM: "));
strcat(dataBuf,fromAddress);
strcat_P(dataBuf,PSTR("\r\n"));
socketSend(dataBuf,strlen(dataBuf),theSocket);
while (socketReceive(dataBuf,sizeof(dataBuf),theSocket)==0)
{
//Serial.println(F("Wait socketReceive retry"));
delay(SOCKET_RECEIVE_RETRY_TIME);
}
//Serial.print(F("socketReceive got "));//Serial.println(dataBuf);
}
if (strncmp_P(dataBuf,PSTR("250"),3)==0)
{
//Serial.println(F("MAIL FROM message was OK"));
strcpy_P(dataBuf,PSTR("RCPT TO: "));
strcat(dataBuf,toAddress);
strcat_P(dataBuf,PSTR("\r\n"));
socketSend(dataBuf,strlen(dataBuf),theSocket);
while (socketReceive(dataBuf,sizeof(dataBuf),theSocket)==0)
{
//Serial.println(F("Wait socketReceive retry"));
delay(SOCKET_RECEIVE_RETRY_TIME);// if there wasn't any data, wait and try again
}
//Serial.print(F("socketReceive 1 got "));
//Serial.println(dataBuf);
if (strncmp(dataBuf,"250",3)==0)
{
//Serial.println(F("RCPT TO message was OK"));
strcpy_P(dataBuf,PSTR("DATA\r\n"));
socketSend(dataBuf,strlen(dataBuf),theSocket);
while (socketReceive(dataBuf,sizeof(dataBuf),theSocket)==0)
{
//Serial.println(F("Wait socketReceive retry"));
delay(SOCKET_RECEIVE_RETRY_TIME);// if there wasn't any data, wait and try again
}
//Serial.print(F("socketReceive got "));//Serial.println(dataBuf);
if (strncmp(dataBuf,"354",3)==0)
{
//Serial.println(F("DATA message was OK"));
strcpy_P(dataBuf,PSTR("SUBJECT: "));
strcat(dataBuf,subject);
strcat_P(dataBuf,PSTR("\r\n"));
socketSend(dataBuf,strlen(dataBuf),theSocket);
strcpy_P(dataBuf,PSTR("FROM: "));
strcat(dataBuf,toFriendlyName);
strcat_P(dataBuf,PSTR(" <"));
strcat(dataBuf,fromAddress);
strcat_P(dataBuf,PSTR(">\r\n"));
socketSend(dataBuf,strlen(dataBuf),theSocket);
strcpy_P(dataBuf,PSTR("To: "));
strcat(dataBuf,toAddress);
strcat_P(dataBuf,PSTR("\r\n")) ;
socketSend(dataBuf,strlen(dataBuf),theSocket);
socketSend(message,strlen(message),theSocket);
strcpy_P(dataBuf,PSTR("\r\n.\r\n"));// termination string
socketSend(dataBuf,strlen(dataBuf),theSocket);
while (socketReceive(dataBuf,sizeof(dataBuf),theSocket)==0)
{
//Serial.println("Wait socketReceive retry");
delay(SOCKET_RECEIVE_RETRY_TIME);// if there wasn't any data, wait and try again
}
//Serial.print(F("socketReceive got"));Serial.println(dataBuf);
if (strncmp_P(dataBuf,PSTR("250"),3)==0)
{
strcpy_P(dataBuf,PSTR("quit\r\n"));
socketSend(dataBuf,strlen(dataBuf),theSocket);
while (socketReceive(dataBuf,sizeof(dataBuf),theSocket)==0)
{
//Serial.println(F("Wait socketReceive retry"));
delay(SOCKET_RECEIVE_RETRY_TIME);// if there wasn't any data, wait 500ms and try again
}
}
else
{
socketClose(theSocket);
return -250;
}
}
else
{
socketClose(theSocket);
return -354;
}
}
else
{
socketClose(theSocket);
return -250;
}
}
else
{
socketClose(theSocket);
return -250;
}
}
socketClose(theSocket);
return 0;
}
else
{
//Serial.println(responseCode);
return responseCode;
}
}