前提・実現したいこと
以下の設定内容でdjangoアプリからメールを送信したいです。
送信元:独自ドメイン
GmailのSMTPサーバーを利用。
こちらの記事を見て、ユーザー作成処理(仮登録後、URLクリックで本登録)の機能を作りました。
Gmailで取得したアカウント(...@gmail.com)の場合は、
問題なくdjangoアプリからメールが送信できます。
しかし、独自ドメインのアカウントからは、以下に記載したエラーがでます。
発生している問題・エラーメッセージ
SMTPAuthenticationError at /user_register/ (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials v190sm53215153pfv.26 - gsmtp')
該当のソースコード
views.py(こちらのコードは、記事の内容と同じなので、おそらく問題ないかと思います。)
python
1class UserCreate(CreateView): 2 """ユーザー仮登録""" 3 template_name = 'app/user_create.html' 4 form_class = UserCreateForm 5 6 def form_valid(self, form): 7 """仮登録と本登録用のメールの発行""" 8 # 仮登録と本登録の切替はis_active属性を使う 9 # 退会処理も、is_active属性をFalseにするだけ 10 user = form.save(commit=False) 11 user.is_active = False 12 user.save() 13 14 # アクティベーションURLの送付 15 current_site = get_current_site(self.request) 16 domain = current_site.domain 17 context = { 18 'protocol': 'https' if self.request.is_secure() else 'http', 19 'domain': domain, 20 'token': dumps(user.pk), 21 'user': user, 22 } 23 24 subject_template = get_template( 25 'app/mail_template/create/subject.txt') 26 subject = subject_template.render(context) 27 28 message_template = get_template( 29 'app/mail_template/create/message.txt') 30 message = message_template.render(context) 31 32 user.email_user(subject, message) 33 return redirect('app:user_register_done')
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = 'サンプル@独自ドメイン.jp' EMAIL_HOST_PASSWORD = '独自ドメインのアカウントで作ったアプリのパスワード' EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'Gmailアドレス@gmail.com'
のように設定すると、
メールは送信されますが、送信元がgmailアドレスになってしまいます。
Gmail の SMTP サーバーを利用して、メールの送信元(EMAIL_HOST_USER)を独自ドメインに設定することはできないのでしょうか?
お分かりになる方、何卒宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/27 08:24
2018/12/27 08:33
2018/12/27 08:35
2018/12/27 08:51
2018/12/27 08:59
2018/12/27 09:00
2018/12/27 09:11
2018/12/27 09:32
2018/12/27 09:32