Hi all,
I've been working on an email alert function for the past few days, and I recently encountered a problem when sending emails to my Gmail account and to my phone (<phone#>@.net). Whenever I try to send alerts to these addresses (in the starred line of code below), the alert does not go through. I've watched the serial monitor as the function is called, and there are no visible issues with the code. I even added in an eRcv function (like the one here) to make sure all the information was being handled correctly, but still no problems showed up. I did some troubleshooting and have learned that the Arduino can still send emails if I use my school address, and I have verified that both my Gmail and phone addresses can receive messages. Is this a bigger issue, or is there a bug in my code that I'm not catching?
NOTE: I was able to receive alerts at all addresses yesterday. I made a series of tweaks and adjustments to my code throughout the day, so I may have taken out something vital. The only other thing I can think of that happened is that I accidentally sent a flood of messages to my phone when a part of my program that contained a call for the email function started looping. Could there be a spam filter that may have blocked all messages from the Arduino?
Anyways, here is the code for my email function:
byte sendMessage(String sysStatus) //sends an alert message
{
if (mclient.connect(mserver,25)) //If the connection is made
{
Serial.println(F("Connected")); //Print confirmation
}
else //If the connection fails
{
Serial.println(F("Connection failed")); //Print negatory
return 0;
}
mclient.println(F("helo localsite.com")); //change to the public IP
mclient.println(F("MAIL FROM: <arduino@localsite.com>")); //Sender is arduino
*****mclient.println(F("RCPT TO: <username@gmail.com>")); //Receiving address*****
mclient.println(F("data")); //send data
Serial.println(F("Sending message...")); //Update on status of message
mclient.println(F("TO: Recipient")); //change to recipient address
mclient.println(F("FROM: <arduino@localsite.com>")); //change to Arduino's address
mclient.println(F("SUBJECT: System Update\r\n"));
if (systemStatus == "EMERGENCY") //If the system is in an emergency state
{
mclient.println(F("WARNING: SYSTEM IN EMERGENCY STATE"));
mclient.println(F("Please contact a member of the lab staff immediately."));
}
else if (systemStatus == "Emergency...Transitioning") //If the system is trying to transition from an emergency state to a stable state
{
mclient.println(F("The system is attempting to recover from an emergency."));
mclient.println(F("Please contact a member of the lab staff immediately."));
}
else if (systemStatus == "Recovered") //If the system has just recovered from an emergency state
{
mclient.println(F("The system has recovered from an emergency."));
mclient.println(F("Please contact a member of the lab staff immediately."));
}
else //For any other states (transition, stable, etc)
{
mclient.println(F("The system is functioning normally."));
}
mclient.println(F("."));
mclient.stop(); //Disconnect from the client
Serial.println(F("Disconnected.")); //Print status of connection
mclient.println("<meta http-equiv=refresh content=0;url=http://localsite.com/>"); //Return to website
return 1;
}