Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gmail Sent email LIMIT
#1
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
Reply
#2
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()
Reply
#3
(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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
(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',
Reply
#5
(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.
Reply
#6
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extract PDF Attachment from Gmail jstaffon 0 536 Sep-10-2023, 01:55 PM
Last Post: jstaffon
  extract email addresses from gmail vigneshboolog 0 1,732 Feb-11-2020, 09:23 AM
Last Post: vigneshboolog
  how to upload a file to my gmail driver after login ?? evilcode1 5 4,099 Nov-06-2018, 07:33 AM
Last Post: evilcode1
  An email with inline jpg cannot be read by all email clients fpiraneo 4 3,931 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Problem with sending text file as an attachment using this Gmail OAuth script downloaderfan 6 6,899 Feb-07-2018, 09:54 PM
Last Post: downloaderfan
  Email - Send email using Windows Live Mail cyberzen 2 5,873 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020