What are the Limit of sending emails through Gmail API using gmailr

692 Views Asked by At

I used the following method to send emails

prepare_and_send <- function(sender, recipient,
                             title, text,
                             attachment) {
  email <- gm_mime() %>%
    gm_to(recipient) %>%
    gm_from(sender) %>%
    gm_subject(title) %>%
    gm_html_body(text) %>%
    gm_attach_file(attachment, type = "pdf")
  email <- gm_attach_part(email,msg) %>%
    gm_send_message() 
}
addresses %>%
  mutate(
    to = sprintf('%s <%s>', name, email),
    from = email_sender,
    subject = sprintf('Logistic options for %s', name),
    msg = sprintf('Dear %s, %s',name,info),
    attachment = sprintf('%s.pdf', attach)) %>%
  mutate(x = pmap(list(from, to, subject, msg, attachment),
                  safely(prepare_and_send)))

I used a CSV file to feed the email recipients and attachments to the 'mime' object.

This is how I authenticated my Gmail API

#Authantication to GmailAPI
use_secret_file("BulkEmailCredentials.json")
gm_auth_configure(key = "client_id",
                  secret = "client_secret"
)

I could successfully send about 500 emails yesterday and I got the following errors afterwards. Error 1:

You have reached a limit for sending mail. Your message was not sent.

Error 2 (example):

Your message to [email protected] has been blocked. See technical details below for more information.

But today I could end only about 150 emails

I also find address not found error for about half of the emails.

I would appreciate it very much if you can explain, the Gmail API limitations and the reason for the above errors?

1

There are 1 best solutions below

0
On

This is a hard limit imposed upon us by gmail itself it has nothing to do with the API you are using.

A gmail user can max send 500 emails a day after that they will be blocked and you will see the You have reached the limit for sending emails error message.

There is a little confusion as to when exactly the block is lifted. As well as when it starts. Some docs state like here that you would need to wait up to 24 hours before you can send emails again.

"When you see this error, you should be able to send emails again within 1 to 24 hours."

In my experience most of these blocks get reset at midnight west cost usa time. Which means that depending upon when you started getting the error message you will have to wait until midnight west cost usa to send mails again however long that is.

Which would mean that Gmails counter starts in West cost usa time. Depending upon where you are in the world. Its hard to define a day for you which may be why you say you have only sent 150 mails and are getting the error. How many did you send yesterday your time? Was yesterday your time still part of gmails counter?

Start your counter midnight west cost USA and keep it under 500 for their full day and see if that doesn't fix your issue.

If it doesn't i would love to hear tough i have been trying to track these weird limits. I would love to add your experience to my notes.