send activation email django-registration (Amazon SES) - python

How to send activation email with username by using django-registration.I've configured Amazon SES on server.
Here is my settings
AWSAccessKeyId='my_key'
AWSSecretKey='my_key'
EMAIL_BACKEND = 'django_ses.SESBackend`
When User trying to register. They get following error message. Will you please help me ? Thank you
NoAuthHandlerFound at /accounts/register/
No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV3Handler'] Check your credentials
I'm doing something wrong? please help
Latest UPDATE
'Check your credentials' % (len(names), str(names)))
NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV3Handler'] Check your credentials
OLD UPDATE
I've made some changes in settings.py
AWS_ACCESS_KEY_ID='my_key'
AWS_SECRET_ACCESS_KEY='my_key'
Now I'm getting following error.
BotoServerError: 400 Bad Request
<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<Error>
<Type>Sender</Type>
<Code>MessageRejected</Code>
<Message>Email address is not verified.</Message>
</Error>
<RequestId>37ceac2e-3861-11e1-acd0-19854590b66c</RequestId>
</ErrorResponse>

You need to verify the email address that you are sending the emails from before amazon will accept the emails.
From the Amazon SES page:
Verify Email Addresses: Before you can send email via Amazon SES, you need to verify that you own the address from which you’ll be sending email. To start the verification process, visit the AWS Management Console.
Before you check whether django-registration can send emails, make sure that sending emails works from the shell
./manage.py shell
from django.core.mail import send_mail
verified_address = "from#example.com"
send_mail('Subject here', 'Here is the message.', verified_address,
['to#example.com'], fail_silently=False)
Any error messages might give you a clue what to try next. If send_mail works, then django registration is probably using the wrong address.

Related

Send email via SES

Do I need an actual mailbox and verified email to send email with SES?
I own the domain I am trying to send from, but I do not have an account or mailbox setup (this is just a test domain, and I don't want to setup a gmail mailbox)
Is there a better way to be doing this in a test environment?
I am using the django-ses package, and sending email like this:
send_mail('Test subject', 'This is the body', 'mypersonalemail#yahoo.com',['info#mydomain.com'])
I very well may have a fundamental misunderstanding of sending email, so any help is appreciated!
In the test environment, you can send messages e-mail only to address registered in sandbox.
At first, you need to verify domain or email address to send from Amazon SES. But you don't need to verify address whom you want to send.
For example,
send_mail('Test subject', 'This is the body', 'mypersonalemail#yahoo.com',
['info#mydomain.com'])
Here, you need to verify mypersonalemail#yahoo.com at AWS SES, not info#mydomail.com.

Python smtplib: Unable to send sms messages to phone

I am trying to send messages to my phone using the SMTP protocol. If I log into my Google Account (for which I've enabled less secure apps) I'm able to send a message to '5551234567#tmomail.net'. The subject and body of the email arrive on my phone as a text message.
However, when I try to do the same with Python's smtplib library, I don't get a message. Here's the code I'm using:
import smtplib
# Establish a secure session with gmail's outgoing SMTP server using your gmail account
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
# the account that will send the emails
server.login('me#gmail.com', 'password')
# sendmail(from, to, msg)
server.sendmail('me#gmail.com', '5551234567#tmomail.net', 'hey there!')
Does anyone know what I can do to get the text message to come through from the smtplib? Any suggestions are very welcome!
Try to check the link below.
If seems like you for forgot
server.ehlo()
How to send an email with Gmail as provider using Python?
Please let us know if you see python message in SENT emails folder of Gmail Inbox.
If yes, try to find a differences between one you sent from browser and one you sent from python API.

Python sending e-mail with SMTP without authentication

I'm making a script that notifies people about some pending tickets in JIRA. These notifications are sent by e-mail, I already got the notification to trigger, but I'm having problems sending the emails.
I can send them using gmail but when I tried to do it with my official account (the one that the company gave me) I am not able to send them. IT guys already provided me the 'localhost' because they use SMTP relays and the port, but they keep telling me that I should start SMTP without authentication, I'm not very sure of how to do this.
The example I found on internet was this:
import smtplib
fromaddr = 'Axel.Sa#mydomain.com'
toaddrs = ['Axel.Sa#mydomain.com']
msg = '''
From: {fromaddr}
To: {toaddr}
Subject: testin'
This is a test
.
'''
msg = msg.format(fromaddr=fromaddr, toaddr=toaddrs[0])
server = smtplib.SMTP('localhost:25')
server.starttls()
server.ehlo("mydomain.com")
server.mail(fromaddr)
server.rcpt(toaddrs[0])
server.data(msg)
server.quit()
But I keep getting this error, If someone can tell me the proper way of sending emails by SMTP without authentication I will be very grateful.
Check this stack:
How to send an email without login to server in Python
change your smtplib.SMTP('localhost:25') to smtplib.SMTP('localhost', 25)

Can't send email with smtp

I want to know why this code can't send email.
import smtplib
content = 'test'
mail = smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login('surapon#gmail.com','222222')
mail.sendmail('surapon#gmail.com','youremail#gmail.com',content)
mail.quit
It shows:
SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 support.google.com/mail/answer/14257 ho10sm6301275pbc.27 - gsmtp')
Later, it shows:
SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbu87\n5.7.14 wdTx8uq_F_WXKXEVia5I3DTMdhzuJL967nviDbOqgBU9lHzjzIHX69az6PFAzff6lA2uGJ\n5.7.14 qCqwJzys1OcoqMzMNUx5o5ja_a3XHatcxE-jqsHjqWCwYR1WVUEmBfGvUIBzgm7iUyGOXq\n5.7.14 RdYOqEx5GLAe05yUhGq-z-JphFKH-x-aA0TwEc-hyEnecghY1ZLtMMsowPhFGa1XGPnNO3\n5.7.14 8XE4yhQctKtYySbTSiQqBUmmV4qE> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 support.google.com/mail/answer/78754 eu5sm6412101pac.37 - gsmtp')
I created yagmail as a package to make it really simple to send emails.
Please try the following:
import yagmail
yag = yagmail.SMTP('surapon#gmail.com', 'password')
yag.send('youremail#gmail.com', subject = 'hi', contents = content)
There are some useful other tricks you can do with the package, such as never having to enter the password again (while still being secure), and it makes it extremely easy to send attachments.
Install with either
pip install yagmail # python 2
pip3 install yagmail # python 3
and for more information please have a look at github.
Due to security issues gmail blocks accessing mail via code or program
But still you can use gmail to send mail via code if you do the following things
What i have done in code :
1.Added a error object to get the error message
import smtplib
try:
content = 'test'
mail = smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login('surapon#gmail.com','222222')
mail.sendmail('surapon#gmail.com','youremail#gmail.com',content)
mail.quit
print "Successfully sent email"
except smtplib.SMTPException,error:
print str(error)
print "Error: unable to send email"
If u ran this code u would see a error message like this stating that google is not allowing u to login via code
Things to change in gmail:
1.Login to gmail
2.Go to this link https://www.google.com/settings/security/lesssecureapps
3.Click enable then retry the code
Hopes it help :)
But there are security threats if u enable it
This is because google considers python SMTPLIB less secure. The link in the error message leads you to the answer.
Within that link there is another link to allowing "less secure" apps to send mail.
https://support.google.com/accounts/answer/6010255
This allows you to specifically allow your application to send email. They provide very little information on what constitutes the security issue.
The link they provide to give explicit access is
http://www.google.com/settings/security/lesssecureapps within the earlier link.
I'll explain what you're trying to do. You're attempting to do an SMTP with the following credentials:'smtp.gmail.com',587
Then you're attempting to login with your gmail creds. Totally wrong.
What you want to do is:
import smtplib
content = 'test'
me = 'surapon#gmail.com'
you = ['someOther#gmail.com']
mail = smtplib.SMTP('localhost')
msg['Subject'] = 'Hello'
msg['From'] = me
msg['To'] = you[0]
#mail.ehlo()
#mail.starttls()
#mail.login('surapon#gmail.com','222222')
mail.sendmail(me, you, msg.as_string())
mail.quit()
Do not include the #gmail.com in your credentials. I used your code with my username (without #gmail.com) and password and was able to send a message.
import smtplib
content = 'test'
mail = smtplib.SMTP('smtp.gmail.com',587)
mail.ehlo()
mail.starttls()
mail.login('surapon','222222')
mail.sendmail('surapon#gmail.com','youremail#gmail.com',content)
mail.quit

Google Appengine sending emails: [Error] unauthorized sender

I'm trying to use google app engine's mail service on my site. It's showing some error whenever I visit the page that sends the email. The error says that I am using an unauthorized sender for the message. Here's the code that sends the email:
mail.send_mail(sender="myapp#appspot.gserviceaccount.com",
to=input_dict["email"],
subject="Mondays user activation",
body=content)
When I try out the site locally (using dev_appserver.py) it doesn't show the error, but it doesn't send the email (Note: I have to add the --enable_sendmail option when I try it locally). The error only shows up when I publish the site.
Does anybody know what I'm doing wrong? Thanks in advance for your help!
What is myapp#appspot.gserviceaccount.com? You might not be able to send mail from that address.
App Engine applications can send email messages on behalf of the app's
administrators, and on behalf of users with Google Accounts.
The email address of the sender, the From address. The sender address
must be one of the following types:
The address of a registered administrator for the application. You can add administrators to an application using the Administration
Console.
The address of the user for the current request signed in with a Google Account. You can determine the current user's email address
with the Users API. The user's account must be a Gmail account, or be
on a domain managed by Google Apps.
Any valid email receiving address for the app (such as xxx#APP-ID.appspotmail.com).
Any valid email receiving address of a domain account, such as support#example.com. Domain accounts are accounts outside of the
Google domain with email addresses that do not end in #gmail.com or
#APP-ID.appspotmail.com.
https://developers.google.com/appengine/docs/python/mail/sendingmail
First follow these steps
https://cloud.google.com/appengine/docs/python/mail/#who_can_send_mail
Then you need to manually add the sender email in cloud console
How to add an authorized sender
You may also have to add the email address you which to send the email from to the App Engine application settings Email API authorized senders.
See https://cloud.google.com/appengine/docs/python/mail/#Python_Sending_mail
Add the unauthorized email address as an administrator here:
https://console.developers.google.com/project/_/permissions/projectpermissions

Categories

Resources