Sending email using Python

Hi,

I tried to send emails from my email provider but I guess their server, at times, takes too long to answer so the blynk-cloud server is causing the script to crush with “BrokenPipeError: [Errno 32] Broken pipe”.

As a remedy, I tried blynk email but it only works when the app is on. Is there a way for the blynk server to send emails on the background?

TIA

The test code:

#!/usr/bin/env python3

import BlynkLib, time

BLYNK_AUTH = '**'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

txt = ""
test = 1

def blynk_loop():
    blynk.set_user_task(checkAC, 10000)
    blynk.run()

def checkAC():
    global txt
    if(test == 1):
      txt = "No AC line at:  "
      txt += time.strftime("%H:%M:%S")
      blynk.email("me@gmail.com", "RPI",txt)
      blynk.notify("No AC!!")
	
	
if __name__ == "__main__":
    while True:
      blynk_loop()

The project may need to be in run mode, but AFAIK the App itself shouldn’t need to be running on the phone.

@Gunner So I thought too.

I ran a test code on an Arduino Yun and on minute 12 I turned off the app. The Yun kept sending the email messages to the cloud blynk server but I stopped receiving them. Then, on minute 21 I turned the app back on and kept receiving the emails again but lost the emails from minute 13 to minute 21.

Apparently, the problem is not Python lib related.

Yun test code:

#include <Bridge.h>
#include <BlynkSimpleYun.h>

char auth[] = "**";

BlynkTimer timer;

void sendemail()
{
  Blynk.email("me@gmail.com", "Subject: my Yun", "Just a test...");
  Console.println("Email sent.");
}

void setup()
{
  Bridge.begin();
  Console.begin();

  Blynk.begin(auth);

  Blynk.email("me@gmail.com", "Subject", "My Blynk project is online.");

  timer.setInterval(60000L, sendemail);     //check for opening time

  delay(1000);
  Console.println("Setup done...");
}

void loop()
{
  Blynk.run();
  timer.run();
}

Results:

Unable to connect: retrying (1)… connected!
Setup done…
09:11:18.158 → Email sent.
09:12:18.141 → Email sent.
09:13:18.145 → Email sent.

09:20:18.171 → Email sent.
09:21:18.144 → Email sent.

09:28:18.138 → Email sent.

Did you stop the project before you killed the app?

Bit confused abut second 12 and 21. You can’t send emails with that frequency.

@Costas Ooops, I ment minute 12 and 21. Will edit my post. I’m using a 60000 delay (1 minute).

No. I need to run the project 24hrs/day so it can alert me if my AC mains have lost power.

Hello @Dmitriy

Could you please confirm that emails from the blynk-cloud server are sent out only when the phone’s app is running even though the project is requesting the email to be sent out?

I tried the above test codes with the blynk-cloud and with a local server with no avail.