AWS SES with GMail (sending only) - amazon-web-services

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?

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.

Related

AWS SES Not Delivering

I am currently using AWS SES to send emails to my users. However, it appears that my users who use outlook / Microsoft's Business Email System are not receiving my emails. SES also tells me that I have no bounces too.
The user's email has {name}.onmicrosoft.com on it.
How can I go about resolving this?
EDIT: Found out that the key phrase "password" is a root cause for the email being blocked and not showing up at all. Not sure how to combat this as I am sending a password reset email.
Thanks

How to send AWS SES email notification from php Application

We have deployed a php application on ec2. We have also configured the ses settings. Now can any share me the settings used in our application to send the bulk mail. I have gone through different settings but totally confused, some people recommend phpmailer, some recommend AWS SDK for PHP.
Please help me. Write now we are using the gmail account to send the email and using the below settings.
$config = array();
$config['protocol'] = 'smtp';
//$config['smtp_crypto'] = 'ssl';
$config['smtp_host'] = 'host';
$config['smtp_user'] = 'test#gmail.om';
$config['smtp_pass'] = '....';
$config['smtp_port'] = 587;
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = 'TRUE';
$config['newline'] = "\r\n";
$this->email->initialize($config);
Can i simply replace the settings with aws ses settings.
If all you want to do is use SES as your SMTP mailer, it really is just a drop in replacement for a regular SMTP server (in your case gmail).
Using the AWS SDK is also an option, and opens up some more SES-specific functionality, but having uses SES for many years on many projects, I have never felt the need, and never felt the need to add in that complexity.
The one thing you might get confused on, is you do not use your regular AWS credentials for this, you need to specifically generate SMTP credentials from the SES section of the AWS console, and then use them for you smtp_user and smtp_pass - they look identical to regular AWS credentials, hence the possible confusion.

How to setup an email address for sending only?

My main goal is to setup an email address for my server to use for sending emails only.
I did some research, and it looked like Amazon Simple Email Server and/or Amazon Workmail could provide me with what I needed. I've gotten as far as setting up SES and Workmail so that I can set my server to be able to send emails. However, I saw that once the Workmail inbox is full (50GB), the account would be unable to send emails. Given that this is going to be used by the server and not a human, I didn't want the inbox to get filled with auto replies, spam, or failed to send messages, and then be unable to send emails. So, I went looking for a way to either:
A) prevent emails from being received and stored in the inbox
B) a rule I could setup to delete anything that didn't match the company domain
C) be able to read the inbox and delete email messages using the AWS CLI, and I'd setup my own script to manage how and what was deleted when
So far I haven't had any luck.
Again, I'm not particular how I achieve the goal, but I do preferably need to find a way to have an email address for a server to use exclusively for sending messages. I worry that if I leave it to employees to remember to login and clear the inbox, someone will forget, and then the server will stop sending emails.
Any direction or advice would be greatly appreciated.
I'm not well versed in email protocols; could I setup the address to return a bounce back always, and that would prevent it from receiving emails into it's inbox?
How are you generating these emails? If you are generating them programmatically (via an app/script), you may not need to set up a server. If you just route the outgoing mail through your app to SNS, the emails will be valid, however, there will be no "inbox" for incoming mail and they will just be dumped. This way you don't have to actually worry about an inbox getting full as it will just drop anything coming in.
https://docs.aws.amazon.com/ses/latest/DeveloperGuide/receiving-email.html
In order to receive emails though SNS, you have to go through the setup linked above, but if you do not set this up, then emails will just bounce. At least, that is how I have been doing it.

Sending SQL emails using AWS and SES

I hope someone will be able to help me with this since I am new with AWS stuff.
I have a Web App using .NET MVC which will be deployed/hosted in AWS. This is the description of what I would like to achieve:
1- Let's say that the Web App will insert products in a Products Table on SQL Server.
2- When this product is inserted, the system (AWS) will send an email to a Client from a Clients Table on SQL Server.
Is that possible with AWS?
Could I set a trigger in SQL Server and send an email by SES?
Is it better to use SQS?. So the Web App will publish messages in SQS, and then having another app listening and sending those emails, for instance a console app.
I will appreciate any direction or useful link.
Thanks all of you in advance.
The answer to your first question is 'yes'. Yes SQL server can use SES to send emails. Because SQL server can send emails, all you need to do is set it up to use the correct SMTP settings from SES once your account is verified and working with SES.
That said, I would never have my db server send emails, just doesn't seem like the right place to do it; even though you can.
I have developed and support several systems like this, and the usual pattern I use is to have the web application insert a message in an SQS queue that will be used as input to another process to send the email out. When possible I like to include all the details about the email into the SQS message, i.e. from, to, subject and the body - everything the downstream process will need to know to send them out.
In my case I use a windows service running on several EC2 instances in an autoscale group to poll the queue and send the emails out. In most cases, where I was able to store all the emails in the SQS body, the windows service is completely general purpose - it reads an SQS message, composes the email and sends it out. Because all of the details of the email are within the SQS message body, this single SQS queue and the windows service that is processing it, can process emails from a variety of applications because the service doesn't need to contain any business logic specific to the application and has no external dependencies.
As you talk about separation of responsibilities, I can't see anything less indicated to send email than a db server (even if it can do it).Sending emails is a task for your business layer, surely not for the data layer.
Use the web app to trigger the process of sending the emails, than implement it directly into the web app, or separate it with a messaging system (like SNS), with a queue system (like SQS) or whatever else.

cfmail, google mail and reply to

I am having problems with google mail with a coldfusion webform, when the form gets sent the reply address is always myemail#myemail.com (substituted). Is this a google mail thing or is there a fix?
<cfmail
from = "#email#"
To = "myemail#myemail.com"
failto="#email#"
server="smtp.gmail.com"
replyto="#email#"
port="465"
useSSL="true"
username="myemail#myemail.com"
password="*****"
Subject = "Confirmation Form"
>
<cfmailparam name="Reply-To" value="#email#">
I don't believe Google Mail allows you to send mail from an address not tied to the account.
I would suggest, regardless of the SMTP server you use, using a real address tied to that domain for the "from" attribute. Set the reply-to and on-behalf-of (I think I got that right) headers to the email of the person "sending" the message.
I will give you one warning about sending lots of automated mail through Google. I was working on a project, and was told to use Google mail to send out a large amount of email. After about a day, they stopped sending out any mail on that account.... but accepted the mail. That is, their SMTP server told CF that the mail had been accepted, then trashed it instead of sending. I'd strongly suggest running your own SMTP server if you send more than a couple dozen emails a day.
I can't remember about personal accounts, but sending mail through Google Apps definitely allows customized Reply To, and this works with replyto attribute of cfmail -- without cfmailparam. Possibly it is the way to handle this problem.