I am trying to send mail with using SES and already setup the mail configuration. Now SES running on production mode -not sandbox-. But in Django App, when I try to send mail nothing happens. it's only keep trying to send, no error.
in setting.py made the configuration.
INSTALLED_APPS = [
'django_ses',
]
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_SES_REGION_NAME = 'ap-northeast-1'
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-northeast-1.amazonaws.com'
and email method.
def send_mail(request, user, emails, subject, path):
current_site = get_current_site(request)
message = render_to_string(f"store/emails/{path}.html", {
"some": "context"
})
send_email = EmailMessage(subject, message, "info#mydomain.com", to=emails)
send_email.send()
By the way I already verified the info#mydomain.com in SES console. And when I try to send email from the SES console using send test email option, I can send without a problem. But in Django App. I can't.
Is there any other settings should I do. Because I can't see any error popping when I try to send mail. It's only keep trying to send. But it can't.
AWS SES provides two types of endpoints: API and SMTP
You are using SMTP one
AWS_SES_REGION_ENDPOINT = 'email-smtp.ap-northeast-1.amazonaws.com'
But 'django_ses.SESBackend' working with API type.
Try to set:
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_SES_REGION_ENDPOINT = 'email.ap-northeast-1.amazonaws.com'
If you want to use usual SMTP connection, you probably need to swap current backend with backends.smtp.EmailBackend and set SMTP connection parameters.
Related
I'm attempting to send email from a very simple Django app. The app is hosted on Heroku, and I have the Mailgun add-on installed. However, whenever I attempt to actually send an email using Mailgun, I get a SMTPServerDisconnected error, with the message Connection unexpectedly closed.
I've gone through almost every tutorial that I can find on the subject, and have still had no luck. My settings.py is exactly as described in the Heroku Mailgun documentation:
EMAIL_USE_TLS = True
EMAIL_HOST = os.environ.get('MAILGUN_SMTP_SERVER')
EMAIL_PORT = os.environ.get('MAILGUN_SMTP_PORT', '')
EMAIL_HOST_USER = os.environ.get('MAILGUN_SMTP_LOGIN', '')
EMAIL_HOST_PASSWORD = os.environ.get('MAILGUN_SMTP_PASSWORD', '')
The os environment variables referenced are managed by Heroku. When I've searched for similar problems, every other question has been using Port 465, however, my port is on 587, which shouldn't have this issue as far as I know.
Currently, I'm using the sandbox domain provided by Mailgun just to attempt to send a test email to a verified recipient email. The following code is used in my views.py to actually send the email, using the django django.core.mail.send_mail() function.
subject = "Thank you for RSVP-ing!"
message = f'Hello World!'
email_from = "mailgun#blannholley.com"
recipient_list = [request.POST.get('email'), ]
send_mail(subject, message, email_from, recipient_list, fail_silently=False)
Any help would be greatly appreciated, as this is my first time attempting to send email over SMTP, so I'm very lost here and feel like I've tried everything.
I am not sure what should I do
from flask import Flask
from flask_mail import Mail, Message
app = Flask(__name__)
with app.app_context():
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_DEFAULT_SENDER'] = 'sender'
app.config['MAIL_USERNAME'] = 'sender'
app.config['MAIL_PASSWORD'] = '*************'
app.config['MAIL_USE_TSL'] = True
mail = Mail(app)
mail.send_message('Mail sent', sender = 'sender', recipients = ['recipients'], body = 'Mail sent successfully')
It tells me
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server I've even enabled emails from less secure apps in gmail. Why does it not seem to work?
I've tried looking the error up and haven't found much of a satisfactory answer yet.
Edit: I used SSL instead of TLS for the encryption and it seems to show me a different error. Now it tells me smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError I have no idea what to do next. I don't know how to enable DisplayUnlockCaptcha. https://accounts.google.com/DisplayUnlockCaptcha is the link for it. I proceeded with what the link said, it told "Account access enabled
Please try signing in to your Google Account again from your new device or application." and I retried, still fail to sign in.
Issue has been fixed!
There are several ways you can try, such as activating ssl
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
You must not enable both tls and ssl together
You need to apply a series of settings to your Gmail account, such as disabling 2FA or Display Unlock Captcha, etc.
The steps of the work are outlined in this tutorial.
https://twilio.com/blog/2018/03/send-email-programmatically-with-gmail-python-and-flask.html
I use django and AWS to send mail.
I have moved my account out of sandbox.
Your account has also been moved out of the sandbox
I use boto and django-ses.
My setting.py is
EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_ACCESS_KEY_ID = '************************'
AWS_SECRET_ACCESS_KEY = '****************************************'
AWS_SES_REGION_NAME = 'us-west-2'
AWS_SES_REGION_ENDPOINT = 'email.us-west-2.amazonaws.com'
And view.py is
from django.core.mail import EmailMessage
from django.core.mail import send_mail
Megti = '*********'
Megco = '*********'
send_mail(
Megti,
Megco,
'XXXX#XXXXXX.com', [aproduct.commail],
fail_silently=False)
I get error:
SESAddressNotVerifiedError at /success/success
SESAddressNotVerifiedError: 400 Email address is not verified.
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>MessageRejected</Code>
<Message>Email address is not verified. The following identities failed the check in region US-WEST-2: XXXX#XXXXXX.com</Message>
</Error>
<RequestId>3cdc4a07-6523-11e7-b493-1d79005a6fdc</RequestId>
</ErrorResponse>
Could someone help me?
When you move out of sandbox, only the recipients' email address need not have to be verified but the Sender's email has to be verified.
Amazon SES Email Sending Errors
You are trying to send email from an email address or domain that you
have not verified with Amazon SES. This error could apply to the
"From", "Source", "Sender", or "Return-Path" address.
Probably your SES is in sandbox mode.
To help prevent fraud and abuse, and to help protect your reputation
as a sender. We place all new accounts in the Amazon SES sandbox.
You can only send mail to verified email addresses and domains, or to
the Amazon SES mailbox simulator.
You can only send mail from verified email addresses and domains.
Visit remove from the Amazon SES sandbox to get out sandbox by contacting support.
I am using django-helpdesk for ticketing system.
its working fine but i am not able to send emails. i am testing this on my localhost.
while i submit a ticket, its getting submitted properly but submitter is not getting any email for newly created ticket.
i added new queue and provided details like E-Mail Address, E-Mail Box Type, E-Mail Hostname, E-Mail Port, Use SSL for E-Mail=False, E-Mail Username, E-Mail Password, IMAP Folder, E-Mail Check Interval properly.
but emails not getting sent.
then i removed all off above from queue and added settings like
QUEUE_EMAIL_BOX_TYPE = IMAP
QUEUE_EMAIL_BOX_SSL = True
QUEUE_EMAIL_BOX_HOST = 'smtp.gmail.com'
QUEUE_EMAIL_BOX_USER = 'email'
QUEUE_EMAIL_BOX_PASSWORD = 'pwd'
but still its not working.
am i missing any settings? please help me out.
QUEUE_EMAIL_BOX settings are not for sending emails, but for receiving them. Configuration for sending emails goes into standard email settings from django.
If you're using SMTP backend (this is default), configuration should be:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'email'
EMAIL_HOST_PASSWORD = 'pwd'
EMAIL_USE_SSL = True
This question already has answers here:
How to change from-address when using gmail smtp server
(6 answers)
Closed 3 years ago.
I put a contact form in my site, and I have this in my settings.py
# Email settings
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'myemail#gmail.com'
EMAIL_HOST_PASSWORD = '****'
EMAIL_PORT = 587
And this in my views.py
name = form.cleaned_data['name']
email = form.cleaned_data['email']
message = form.cleaned_data['message']
subject = 'Email from ' + name
content = name + '\r\n' + email + '\r\n\r\n' + message
send_mail(subject, content, email, ['me#myemail.com'])
It all works correctly, i get the email with all the information, but, the email comes from myemail#gmail.com even though the from_email parameter has the email var with the senders email.
It doesn't work that way or i'm doing something wrong?
I wanted to get the email from the sender, so y can just reply to it, like i do in PHP.
Thank you.
Gmail will not let you spoof where the email came from.
per user iAn in a similar post
The short answer - you can't.
Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.
The SMTP feature of gmail isn't intended to be an open or relay service. If it allowed any values for the From header, it would significantly dilute Google's standing with spam services, as there would be no way to verify the credentials of the sender.
You need to consider alternatives. How are you planning to host your script/application/website when it's finished: virtually every hosting solutions (shared/vps/dedicated server) will come pre-configured with an email transfer solution: be it sendmail or postfix on *nix, or IIS on Windows.
If you are intent on using gmail then you could:
Setup a dedicated "myapp#gmail.com" account
If you own the domain you are supposedly sending from, use the free gmail for domains, and setup a "myapp#mydomain.com" account.