• Skip to main content
  • Skip to primary sidebar

学習記録

Djangoのviewからメール送信

2021年6月15日 by 河副 太智 Leave a Comment

SendGridの登録方法はLearnDjango様のページ下部Email Serviceを参考

view.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from django.core.mail import send_mail
#メール送信
subject = "Thank you for your subscription to xxx."
message = "Dear " + name + "\n\nThank you for your subscription to xxx. \nHere is your Subscriptiondetail " \
"\n\nInvoice.No: " + invoice +\
"\nSubscription ID: " + stripe_customer_id +\
"\nApplication date: " + date +\
"\nName: " + name +\
"\nMonthly Subscription Fee: " + currency.upper() + " " + price_new +\
"\n\nYou will be charged " + currency.upper() + " " +  price_new + " every month until you cancel your subscription."\
"\n\nif you have any question please reply this email.\n\nBest Regards \n\nxxx\nxxx."
 
from_email = 'xxx@xxx.com'
admin_email = ['xxx@xxx.com',customer_email ]
print("send")
try:
    send_mail(subject ,message, from_email, admin_email)
except:
    import traceback
    traceback.print_exc()

settings.py

1
2
3
4
5
6
7
DEFAULT_FROM_EMAIL = 'xxx@xxxx.com'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'apikey'
EMAIL_HOST_PASSWORD = 'SG.j2IQBU_xxxxxxxxxxxxxxxxxxxxxxxxxx'
# EMAIL_HOST_PASSWORD = 'customsxxxxxx'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

 

 

このエントリーをはてなブックマークに追加

Tweet
[`yahoo` not found]
このエントリーを Google ブックマーク に追加
LinkedIn にシェア
LINEで送る


Filed Under: Django

Reader Interactions

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in