how to send email in kivy?

180 views
Skip to first unread message

Luigi Marongiu

unread,
Jul 2, 2020, 1:33:38 AM7/2/20
to Kivy users support
Hello,
I would like to send an email via kivy. I have followed the tutorial https://realpython.com/python-send-email/ thus I set:
```
import smtplib, ssl

class clockLabel(Label): # the email is sent according to the time with a clock application
sender_email = "my@gmail"
receiver_email = "m...@outlook.com"
message = "Hello, world!"
ctx=ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=ctx) as server:
       server.login("my", password)
       server.sendmail(sender_email, receiver_email, message)
```
but I get:
```
     raise SMTPAuthenticationError(code, resp)
 smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials d20sm7068660edy.9 - gsmtp')
```
Same thing if I use m...@gmail.com in server.login.

How can I send emails in kivy?
Thank you

K leo

unread,
Jul 2, 2020, 2:41:07 AM7/2/20
to Kivy users support
Did you test in simple Python (i.e. without Kivy) your send email routine?

James D

unread,
Jul 2, 2020, 4:22:57 AM7/2/20
to Kivy users support
Gmail requires you to enable the ability to send emails from a program like that without two factor authorisation.
Not sure where it is but you have to log into your Gmail account.
Gmail classes it as less secure
Hope you can find it

James D

unread,
Jul 2, 2020, 4:25:14 AM7/2/20
to Kivy users support
If you search
gmail enable less secure apps
Hopefully will point you in the right direction

Luigi Marongiu

unread,
Jul 2, 2020, 4:26:44 AM7/2/20
to Kivy users support
I have not tried in a simple python, since Kivy and Python do overlap.
Maybe doing it into a class interferes?
I understood that `server.login("my", password)` or
`server.login("m...@gmail.com", password)` should assure the login...
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fe149315-75a3-4d49-945b-ccd9885663bbo%40googlegroups.com.



--
Best regards,
Luigi

Elliot Garbus

unread,
Jul 2, 2020, 9:57:40 AM7/2/20
to kivy-...@googlegroups.com

I would recommend creating a simple test outside of kivy, to ensure you have the email part working.  The integration with Kivy should be trivial.  While I have not sent email, I have accessed web based JSON APIs, XML and used AWS  within kivy without issue.

Robert Flatt

unread,
Jul 2, 2020, 1:18:08 PM7/2/20
to Kivy users support
The issue is almost certainly not related to Kivy.

First get the behavior running with a simple Python script.
As James says for a Google smtp server you have to log in to google and "enable insecure mail access"
Next for the moment forget SSL, use smtplib.SMTP()
I expect SSL will require some additional setup.

On Thursday, July 2, 2020 at 3:57:40 AM UTC-10, Elliot Garbus wrote:

I would recommend creating a simple test outside of kivy, to ensure you have the email part working.  The integration with Kivy should be trivial.  While I have not sent email, I have accessed web based JSON APIs, XML and used AWS  within kivy without issue.

 

From: Luigi Marongiu
Sent: Thursday, July 2, 2020 1:26 AM
To: Kivy users support
Subject: Re: [kivy-users] Re: how to send email in kivy?

 

I have not tried in a simple python, since Kivy and Python do overlap.

Maybe doing it into a class interferes?

I understood that `server.login("my", password)` or

`server.login("m...@gmail.com", password)` should assure the login...

 

On Thu, Jul 2, 2020 at 10:23 AM James D <jsdav...@gmail.com> wrote:

> Gmail requires you to enable the ability to send emails from a program like that without two factor authorisation.

> Not sure where it is but you have to log into your Gmail account.

> Gmail classes it as less secure

> Hope you can find it

> --

> You received this message because you are subscribed to the Google Groups "Kivy users support" group.

> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fe149315-75a3-4d49-945b-ccd9885663bbo%40googlegroups.com.

 

 

 

--

Best regards,

Luigi

 

--

You received this message because you are subscribed to the Google Groups "Kivy users support" group.

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Luigi Marongiu

unread,
Jul 3, 2020, 1:24:53 AM7/3/20
to Kivy users support
I launched the commands from a single python file, and I got this
email from Google:
```
Sign-in attempt was blocked for your linked Google Account
m...@gmail.com
Someone just used your password to try to sign in to your account from
a non-Google app. Google blocked them, but you should check what
happened. Review your account activity to make sure no one else has
access.
```
How can I use smtplib.SMTP?
Thank you
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/86dc1e55-79ee-4692-a519-34a6e566cc4bo%40googlegroups.com.



--
Best regards,
Luigi

Luigi Marongiu

unread,
Jul 3, 2020, 1:27:07 AM7/3/20
to Kivy users support
Addendum:
I have found these tutorials for smtplib.SMTP:
https://www.tutorialspoint.com/python/python_sending_email.htm
https://www.afternerd.com/blog/how-to-send-an-email-using-python-and-smtplib/

On Thu, Jul 2, 2020 at 7:18 PM Robert Flatt <planckp...@gmail.com> wrote:
>

James D

unread,
Jul 3, 2020, 2:49:51 AM7/3/20
to Kivy users support
Can you confirm you have enabled less secure apps to access Gmail.
(

Luigi Marongiu

unread,
Jul 3, 2020, 3:39:22 AM7/3/20
to Kivy users support
I did it now -- I received the email:
```
Access for less secure apps setting has been turned on for your Google
Account m...@gmail.com. If you didn't change it, you should check what
happened.
```
I'll try logging in again later...
Thank you

On Fri, Jul 3, 2020 at 8:49 AM James D <jsdav...@gmail.com> wrote:
>
> Can you confirm you have enabled less secure apps to access Gmail.
> (
>
> --
> You received this message because you are subscribed to the Google Groups "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f3722b43-fb0e-4c0e-bd17-0bbf8d2e74beo%40googlegroups.com.



--
Best regards,
Luigi

Andrei Sima

unread,
Jul 3, 2020, 6:06:31 AM7/3/20
to Kivy users support
If it is just a test env the warning message can be ignored.
I use Gmail for Django dev env and I get that all the time.

In production, if you need to set up Gmail, you should do it via a dedicated Gmail app/Gmail API.
I have used it in production only once, a long time ago, and I do not remember all the setup details (also might be obsolete time.now()).

As Robert pointed out you can forget about SSL it will not work on "less secure apps". Only TLS will work.

P.S.
I guess you can grab Django send_mail()
docs:
and implement it in your app.
!!! Pay attention to django.conf.settings since there are the settings for your mail account.

____________________
Andrei Sima


Luigi Marongiu

unread,
Jul 3, 2020, 7:30:42 AM7/3/20
to Kivy users support
This time it worked, from python.

On Thu, Jul 2, 2020 at 7:18 PM Robert Flatt <planckp...@gmail.com> wrote:
>
Reply all
Reply to author
Forward
0 new messages