0

Our business uses G Suite for its emails. Currently we have a number of automated emails that are sent using MailKit in .Net Core code. This has been working fine until yesterday where we had to send a large number of emails (around 600) in one go. Around 60 emails were sent successfully, but the rest all failed with errors like this which were returned from Gmail:

4.7.0 Temporary System Problem. Try again later (10). i4sm4226208wrr.17 - gsmtp

Which I believe is Gmail telling me it’s been overloaded: https://stackoverflow.com/a/39108563/5392786

I’m guessing Google has a restriction on how many emails you can send in this way?

A lot of our infrastructure is on AWS so I have considered switching to AWS SES to handle our automated emails. Is this a viable option?

I still want the rest of the business to be able to continue using Gmail as their email client. Is it possible to use AWS SES in parallel with Gmail for sending emails from code (using the AWS SDK), but leave the receiving of emails as it is (i.e. SES doesn’t have anything to do with receiving or handling incoming emails, it just sends emails when I tell it to from code)?

EDIT Here's the code I'm using to send the emails:

public async Task SendEmail(MimeMessage message)
{
    var certificiate = new X509Certificate2("certificate.p12", "notasecret", X509KeyStorageFlags.Exportable);
    var credentials = new ServiceAccountCredential(
        new ServiceAccountCredential.Initializer("automatedemails@automatedemails-######.iam.gserviceaccount.com")
        {
            Scopes = new[] { GmailService.Scope.MailGoogleCom },
            User = ((MailboxAddress)message.From.First()).Address
        }.FromCertificate(certificiate));

    if (!await credentials.RequestAccessTokenAsync(new CancellationToken()))
    {
        throw new ApplicationException("Error requesting access token for Gmail authentication");
    }

    using (var client = new SmtpClient())
    {
        client.Connect("smtp.gmail.com", 587, SecureSocketOptions.StartTls);

        var oauth2 = new SaslMechanismOAuth2(credentials.User, credentials.Token.AccessToken);
        client.Authenticate(oauth2);

        await client.SendAsync(message);
        client.Disconnect(true);
    }
}

This is run for every email. I wonder if it's because I'm opening and closing the connection for every email?

Andy Furniss
  • 3,814
  • 6
  • 31
  • 56

1 Answers1

2

Yes, you can use SES as an additional sender. Unless you specifically set it up to do so, incoming emails will be left as is and will behave as usual.

In fact, you could even have one application sending emails using gsuite, a second application sending emails from SES, and all the users all still using gsuite to send and recieve emails and it would still work fine.

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • Excellent, thank you for the information! Having the ability to use GSuite and SES in different applications simultaneously would be a bonus as then I can gradually migrate my applications over, one at a time. Do you know if the change to SES will solve my original issue with the overloading of Gmail's SMTP? Or do you have any supplementary info/links on the issue? – Andy Furniss Jul 05 '19 at 11:34
  • 2
    It should, if you are using SES as one of your email servers for large amounts of outgoing email, it completely bypasses Gmail's SMTP server. – E.J. Brennan Jul 05 '19 at 13:27