Skip to content
Advertisement

sending random messages with smtplib python

I want to send random messages using smtplib in python, I wrote this code:

JavaScript

I’ve received the messages but with the same string, I also tried to make a list of random strings and then make the message variable chose randomly from there using random.choice() but it didn’t work either.

What could the problem be?

Advertisement

Answer

Your mistake: generating one message with message=generator() and using that same message inside the loop. This is why it is always the same string.

You should call generate() every time you iterate through the while loop like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement