Python Forum

Full Version: Gmail Sent email LIMIT
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I created a program, it sends email fine.
However there is a limit (100) in the number of emails it can send before it crashed and gives
an error.

Does someone know what is going on ?
Thanks !

server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.login(gmail_sender, gmail_passwd)
    BODY = '\r\n'.join(['To: %s' % TO, 'From: %s' % gmail_sender, 'Subject: %s' % SUBJECT, '', TEXT])
    server.sendmail(gmail_sender, [TO], BODY)
the error message is.
Error:
File "C:\ProgramData\Anaconda3\lib\smtplib.py", line 398, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed") SMTPServerDisconnected: Connection unexpectedly closed
Fixed your code tag look at BBCode
Add this to see the actual smtp conversation before it raise error.
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
(Apr-27-2021, 02:11 AM)Johnse Wrote: [ -> ]Does someone know what is going on ?

Yes, Google blocks spammer. I guess you can read it somewhere in the policy.

If you want to send Newsletters, you have to use your own SMTP-Server with a fixed IP or a service provider for this task. For example, mailgun offers a newsletter-service with an API for programmers.
(Apr-27-2021, 08:29 AM)snippsat Wrote: [ -> ]Fixed your code tag look at BBCode
Add this to see the actual smtp conversation before it raise error.
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()

thanks for that line of code.
I have the login in the loop so the message is saying too many login attempt.

I move the login code out of the loop and now I got another error message.


Error:
File "<ipython-input-56-9108101ba83e>", line 24, in <module> server.sendmail(gmail_sender, [TO], BODY) File "C:\ProgramData\Anaconda3\lib\smtplib.py", line 871, in sendmail raise SMTPSenderRefused(code, resp, from_addr) SMTPSenderRefused: (421, b'4.7.0 Try again later, closing connection. (MAIL) a189sm523022qkd.46 - gsmtp',
(Apr-27-2021, 02:35 PM)DeaD_EyE Wrote: [ -> ]
(Apr-27-2021, 02:11 AM)Johnse Wrote: [ -> ]Does someone know what is going on ?

Yes, Google blocks spammer. I guess you can read it somewhere in the policy.

If you want to send Newsletters, you have to use your own SMTP-Server with a fixed IP or a service provider for this task. For example, mailgun offers a newsletter-service with an API for programmers.

Its there a way to do it with google mail and by pass the "blocks spammer".
I am going to look into mailgun, never heard of it.
(Apr-28-2021, 07:52 PM)Johnse Wrote: [ -> ]Its there a way to do it with google mail and by pass the "blocks spammer".
If you need to send many mail from a Python app from own IP/server,you should not login for each mail you send.
So want to reuse a connection without closing it,then can send may mail with one login.
Something like this setup.
(Apr-28-2021, 07:52 PM)Johnse Wrote: [ -> ]I am going to look into mailgun, never heard of it
We had some trouble with Gmail for your internal outgoing mail,so we switch to Amazon(SES).
Have work fine and stable with them.
This is often called Transactional Email.
Quote:Transactional email: Services to send bulk email messages via an API or SMTP server."- AUTHOR