Use flask-mail with Amazon SES - flask

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

Related

Sending email with Django using Gmail not working

I'm new to Django and I want to send the email through my Django server using my Gmail account but unfortunately, I'm getting an error while sending emails even though I've put all credentials correctly there is one thing more in my Gmail account which is "less secure apps" that has to be enabled but this feature is no longer available in Gmail so now how can I send the emails in Django?
error while sending the email
b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials f14-20020a05600c4e8e00b0039c5642e430sm4688852wmq.20 - gsmtp'
Since May 30 2022 the less secure apps feature has been disabled. Now, to let 3rd party apps access gmail you must generate an App password and to generate an app password you must first enable 2-factor authentication for your account:
https://myaccount.google.com/apppasswords
Once you have the app password you can simply replace your host account password with the app password:
EMAIL_HOST_PASSWORD = '<app_password>'
You can find the complete email integration process wonderfully explained here: https://github.com/CoreyMSchafer/code_snippets/tree/master/Django_Blog/12-Password-Reset/django_project
im looking forward for an answer too, as i am experiencing the same problem.
In the meantime, i had to change the email provider to another company, for me it worked with mailjet, they have a free plan and no card info needed, hope this helps you!

Convenient and simple solution to receive and answer emails in a small Django app

I am developing a Django app which uses Email in some of its components (but not at its core). I am looking for a simple and cheap solution that satisfies the following requirements:
Only the custom domain of the app is used (no username#gmail address)
Django can send emails programmatically (error reporting, user data from forms)
The admin can receive and and answer mails through an email client of their choice
The provider should allow sending mass emails (not a priority)
The solution does not need to be free
Solutions I have considered so far:
Using my hosting provider: They understandably don't support custom email accounts for VPS customers
Amazon SES: would work for sending email, but received emails would land in a S3 bucket; it is unclear to me how to connect this to an email client
Sendgrid: would work for sending email, but the only way to handle inbound mail is to forward it as HTTP POST request to a view
Django extensions to read and send email through the admin interface: I can't use my email client
Google Workspace: seems like this could work. My issue is that it includes a lot of functionality I don't really need. Does anyone have experience with this?
All I really need is to alias a standard email account to my custom domain.
You can create your custom domain email account with any provider that supports SMTP clients (including Google Wspace) and configure the SMTP credentials into Django's email backend (or use a fancier email package, like for exmaple Django-Anymail).
in settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.email_provider_server.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email_account_user_name'
EMAIL_HOST_PASSWORD = 'secret_password'
EMAIL_USE_TLS = True
Receive emails and reply through the provider's webmail or configure IMAP/SMTP in a desktop client like Outlook/Thunderbird/WindowsMail etc.
The provider will give you the IMAP/SMTP settings. Best practice is to feed the password into Django's settings.py through environment variables etc. for security.

discourse can't send email

i installed a discourse on AWS bitnami edu3d.co. I did the following things but still can't send the login verification email.
config the discourse by this instruction https://docs.bitnami.com/bch/apps/discourse/configuration/configure-smtp/
in AWS, request email sending limits
in AWS, verify my email identity,
in AWS, send test email (it is correct)
create my credential
checked spam boxes (no email)
Thank you!
The problem is solved. I guess problem is that I set the username and password wrongly.
smtp_address = ''
smtp_port = 587
smtp_domain = 'edu3d.co'
smtp_user_name = ''
smtp_password = ''
smtp_enable_start_tls = true
smtp_authentication = login
If you have problem in setting smtp for the discourse installed on AWS EC2 bitnami. You can do the following checks.
1) check whether your VM instance can connect the smtp server (test if smtp_address and smtp_port are correct)
I found 25 is not responding and 465 sometimes broke too, 587 works well.
2) check whether your username and password set correctly.
AWS provides this instruction https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-smtp-client-command-line.html
How I find the problem
I really can't figure out why the smtp setting is 'correct' but i just can't receive the email. So I changed to gmail, the setting is a bit easier than AWS SES. After change, I received the email immediately but it says the login method is not secure so Google blocked it. This proves the smtp setting is working. And according to previous test, my VM instance can connect to the smtp server. So there should have something wrong in the smtp setting.
I go to AWS SES, intending to check the my credential. But I can only create a new one. So I did, then I found I misunderstood the username and password. After change, the email is working. Great!
The following instruction is very helpful!
https://docs.bitnami.com/bch/apps/discourse/configuration/configure-smtp/

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.

AWS SES verified emails

Trying to understand something thats not clear from AWS SES emails.
I have a simple emailer on my website that I have setup using nodemailer.
It has 3 fields
Name: name of user filling out form
email: email address of user filling out email.
Description: description filled out by user.
I'm seeing in AWS docs that I need to verify on their console the users email.
You can only send mail from verified email addresses and domains.
Note: This restriction applies even when your account isn't in the
sandbox.
This could be any number of different user email address how would I be able to verify them all I wouldn't know them.
What am I not getting here. I have verified the To: email which will always be the same as its coming to my domain email.
You'll want to send from an email address under your control (SES enforces this on a technical level, but spam filters tend to de facto enforce this everywhere due to things like SPF records) with a Reply-To header of the email address submitting the form.