How to send AWS SES email notification from php Application - amazon-web-services

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.

Related

Use flask-mail with Amazon SES

I want to use Flask mail with Amazon SES. I know it's possible to use the boto library instead, but in the long term, I want to use different smtps. (this is thus a different question than How to adapt flask-mail to support two SMTP accounts)
So, I registered in Amazon SES, and got a client id and secret id. I have also registered the mail adress with which I want to send emails in my application. Now, my question is, how should I configure my application (see below variables)?
MAIL_USERNAME = config.get('mail_service', 'USER')
MAIL_PASSWORD = config.get('mail_service', 'PASSWD')
MAIL_SERVER = config.get('mail_service', 'MAIL_SERVER')
MAIL_PORT = 587
For MAIL_SERVER, I already found it. However, for username and password, I'm not sure how to provide both mail_adress (example#gmail.com), client_id (SES) And both password (mail password + secret_id from SES).
Any ideas?
Thanks a lot

AWS Autogenerated Email

I hired out the development of an app/database project and received something that works, but not as I requested.
When a user downloads the app and creates an account, an AWS autogenerated email goes out with a temporary password and a prompt to change that password.
The problem is that the email contains two other company names! The developers must have used a template and forgot to change the text. I need some guidance on finding the AWS service that sends the email so I can change the outgoing message. Would this be a SES function? Lambda? I'm at a loss.
I've asked the developers for pointers to the right AWS services but they won't acknowledge my emails. It's on me to fix this and I don't know where to start.

AWS SES with GMail (sending only)

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.

Send email with custom from with amazon ses for several domains

How can I accomplish to send email in Amazon SES with a custom email from for several domains.
For example, I have an application that is used by several clients, and we have a module to send emails. When we send an email it goes with the "amazonses.com domain", but what I want to accomplish is a custom from email for each client, each one has a different domain.
The process for doing this is entirely specific to the current SES configuration steps so its better I provide a link thats regularly updated.
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/mail-from-set.html
The short summary is that you can do this by choosing a FROM option for the emails you are sending from.
Programmatically Setting From
The link above points how how to use the API to programmatically change the FROM value. The link below is directly to the API call for setting from but to accomplish it you'd still need to follow the manual tutorial then replace its steps with equivalent API Calls.
http://docs.aws.amazon.com/ses/latest/APIReference/API_SetIdentityMailFromDomain.html

how to do django SMTP setting using aws instance with EIP and default domain name

Have took 2 day, can't find a good method.
1.AWS Linux instance have pre-install sendmail, I only need to send out email. But don't how to configure sendmail and other package.
2.Try to use AWS SES, however it needs to verify domain, which means I need to deal with AWS Router 53. After reading very complicated document and "create hosted zone", the AWS SES domain verification still "pending" after 24 hours. I am guessing maybe the default EIP domain name, like "ec2-***-amazonaws.com" is not a qualified/Registered domainn ?
As a newbie for SMTP setting, really don't know what to do? Since even if using a free mail server, it seems still need to 'verify domain', if aws default domain name "ec2-***-amazonaws.com" is invalid, how can I pass the domain verification?
By the way, since sendmail is pre-install, and this website is very simple, small group used, how to set configuration and other package to do email server on this instance itself?
Any suggestion is appreciated!
Thank you
It's much easier if you configure email from your Django app directly to a third party email provider, effectively by-passing the local sendmail configuration altogether. Trying to set up an email connection to AWS/SES on the server itself is also a pain, it's also much easier to configure the Django app to connect directly to AWS/SES
You have three very popular choices to setup email from Django:
Set up a connection to Gmail/Google apps .- If you'll be sending a lot of email volume I wouldn't recommend this option, because they block you easily if you use it to relay a lot of email.
Set up a connection to AWS/SES.- You mention you already tried this, but now try to set the connection inside Django using the Python packages boto and django-ses, this will make the email setup much easier. In addition, boto is also useful if you plan to use some other AWS service like S3.
Set up a connection to Mandrill.- This is another provider, not as big as Google or AWS, but they provide good service with decent free email volume and you can also set up a connection directly from Django.
Take a look at this article -- which I wrote -- that describes all the set up steps for all three providers in detail:
http://www.webforefront.com/django/setupdjangoemail.html