Go Down

Topic: Problem Sending Email With GSM SIM8000L. (Read 51 times) previous topic - next topic

lawrenceMC

Hey guys,
I have been trying to send emails with the GSM SIM800l but it doesn't work properly.
It is sending an email but instead of setting the body of the email to the specified text,
it sends the whole command set as the email body.
I have used the following document for commands.

Here is My code
Code: [Select]

#include <SoftwareSerial.h>
#define SERIAL_BUFFER_SIZE 512
SoftwareSerial sim(10, 11);

String sender = "\"user@email.com\"";
String pass = "\"*******\"";
String reciever = "\"reciever@gmail.com\"";
String user1 = "\"user\"";
String user2 = "\"reciever\"";
String subject = "\"Email subject\"";
String body = "\"This is the email body\"";
String server = "\"mail.email.com\",";
int port = 587;
String apn = "ISP apn name";
String _output;

void setup()
{
  delay(7000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(57600);
  Serial.println("System Started...");
  sim.begin(57600);
  delay(1000);
  sim.println("ATE1");
  sim.println("AT+SAPBR=3,1,\"contype\",\"GPRS\""); // configure bearer profile 1
  sim.println("AT+SAPBR=3,1,\"APN\"," + apn);       //configure Access point name
  sim.println("AT+SAPBR=3,1,\"USER\",\"apn user name\"");     //
  sim.println("AT+SAPBR=3,1,\"PWD\",\"apn password\"");;
}

void loop()
{
  dataOn();
  delay(100);
  sendEmail();
  _readSerial();
  delay(120000);
  dataOff();
}

void dataOn()
{
  sim.println("AT+SAPBR=1,1"); // open GPRS context
}

void dataOff()
{
  sim.println("AT+SAPBR=0,1"); //GPRS OFF
}
void sendEmail()
{
  Serial.println("SIM800L Send an email");
  int sec = 1;
  sim.println("AT+EMAILCID=1"); //set email parameters
  sim.println("AT+EMAILTO=30");
//  sim.println("AT+EMAILSSL=1");
  sim.println("AT+SMTPSRV= " + server + port);
  sim.println("AT+SMTPAUTH=1," + sender + "," + pass);
  sim.println("AT+SMTPFROM="+ sender+ ","+ user1);
  sim.println("AT+SMTPRCPT=0,0,"+ reciever+","+ user2);
  sim.println("AT+SMTPSUB=" + subject);
  sim.flush();
  Serial.flush();
  sim.println("AT+SMTPBODY=512");
  delay(100);
  sim.println("AT+SMTPBODY="+ body);
  sim.println((char)26); 
  delay(1000);
//  sim.println(0x1A);
  sim.println("AT+SMTPSEND");
}

String _readSerial(){
  while(sim.available()){
   _output = Serial.readString();
  }
  return _output;
}



PaulS

Why are the values of all of your String in quotes?
The art of getting good answers lies in asking good questions.

Go Up