TL; DR:資格情報が渡されたにもかかわらず、DjangoアプリからCelery/RabbitMQタスクを使用して電子メールを送信しようとすると、SMTPAuthenticationErrorがGmailから届きます。 Celeryを使用せずにメールが正常に送信された場合、これは発生しません。djangoセロリでメールを送信するときのGmail認証エラー
こんにちは、
私は非同期的に私のDjangoアプリケーションにセロリ/ RabbitMQのを使用して、ユーザーに電子メールを送信しようとしています。私は通常、メソッドを呼び出すと
from grad.celery import app
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template
from django.template import Context
from grad import gradbase
from time import sleep
from grad import settings
@app.task
def send_transaction_email(student_data, student_email):
html_email = get_template('grad/student_email.html')
context = Context({
'name': student_data['name'],
'university': student_data['university'],
'data': student_data,
'shorturl': gradbase.encode_graduation_data(student_data)
})
msg = EmailMultiAlternatives('Subject Here',
'Message Here',
'[email protected]',
[student_email])
msg.attach_alternative(html_email.render(context), "text/html")
msg.send()
:私は、電子メールを送信するために、次のコードを持っている
tasks.send_transaction_email(entry, stud_email)
電子メールが細かい送信されますが、私はそうのようなセロリのタスクへの呼び出しを委任する場合:
tasks.send_transaction_email.delay(entry, stud_email)
私は、次のトレースを取得:
Traceback (most recent call last):
File "/Users/albydeca/Gradcoin/venv/lib/python2.7/site- packages/celery/app/trace.py", line 240, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/albydeca/Gradcoin/venv/lib/python2.7/site-packages/celery/app/trace.py", line 438, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/albydeca/Gradcoin/grad/tasks.py", line 27, in send_transaction_email
msg.send()
File "/Users/albydeca/Gradcoin/venv/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Users/albydeca/Gradcoin/venv/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/Users/albydeca/Gradcoin/venv/lib/python2.7/site- packages/django/core/mail/backends/smtp.py", line 69, in open
self.connection.login(self.username, self.password)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 622, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials q8sm53748398wjj.7 - gsmtp')
基本的には、クラッシュを引き起こす前に2行に文字通り印刷するにもかかわらず、Gmailは認証情報を認識しません。
誰かが私を助けることができますか?
良いアイデアですが、現時点でGスイートの料金を実際に支払う必要はありません。私はそれを "DisplayUnlockCaptcha"機能を使って修正しました。 –
私は通常、 "G Suite SMTP relay"ではなく "Gmail SMTP server"を使用しています。開発には問題ありません。また、回答があなたの問題を解決した場合は、賛成/承認してください。 – McAbra