|
| 1 | +defmoduleGroupherServer.Emaildo |
| 2 | +@moduledoc""" |
| 3 | + the email dispatch system for Groupher |
| 4 | +
|
| 5 | + welcom_email -> send to new register |
| 6 | + """ |
| 7 | +importBamboo.Email |
| 8 | +importHelper.Utils,only:[get_config:2] |
| 9 | + |
| 10 | +aliasGroupherServer.Accounts.User |
| 11 | +aliasGroupherServer.Billing.BillRecord |
| 12 | + |
| 13 | +aliasGroupherServer.Email.Templates |
| 14 | +aliasGroupherServer.Mailer |
| 15 | + |
| 16 | +@support_emailget_config(:system_emails,:support) |
| 17 | +@admin_emailget_config(:system_emails,:admin) |
| 18 | + |
| 19 | +defwelcome(%User{email:email}=user)whennotis_nil(email)do |
| 20 | +base_mail() |
| 21 | +|>to(email) |
| 22 | +|>subject("欢迎来到 coderplanets") |
| 23 | +|>html_body(Templates.Welcome.html(user)) |
| 24 | +|>text_body(Templates.Welcome.text()) |
| 25 | +|>Mailer.deliver_later() |
| 26 | +end |
| 27 | + |
| 28 | +# user has no email log to somewhere |
| 29 | +defwelcome(_user)do |
| 30 | +{:ok,:pass} |
| 31 | +end |
| 32 | + |
| 33 | +defnotify_admin(%User{from_github:true}=user,:new_register)do |
| 34 | +base_mail() |
| 35 | +|>to(@admin_email) |
| 36 | +|>subject("新用户(#{user.nickname})注册") |
| 37 | +|>html_body(Templates.NotifyAdminRegister.html(user)) |
| 38 | +|>text_body(Templates.NotifyAdminRegister.text()) |
| 39 | +|>Mailer.deliver_later() |
| 40 | +end |
| 41 | + |
| 42 | +defnotify_admin(_user,:new_register)do |
| 43 | +{:ok,:pass} |
| 44 | +end |
| 45 | + |
| 46 | +defnotify_admin(%BillRecord{}=record,:payment)do |
| 47 | +base_mail() |
| 48 | +|>to(@admin_email) |
| 49 | +|>subject("打赏#{record.amount} 元") |
| 50 | +|>html_body(Templates.NotifyAdminPayment.html(record)) |
| 51 | +|>text_body(Templates.NotifyAdminPayment.text()) |
| 52 | +|>Mailer.deliver_later() |
| 53 | +end |
| 54 | + |
| 55 | +# some one comment to your post .. |
| 56 | +# the author's publish content being deleted .. |
| 57 | +defnotify_author,do:IO.inspect("notify_author") |
| 58 | +defnotify_publish,do:IO.inspect("notify_publish") |
| 59 | +# ... |
| 60 | + |
| 61 | +defpbase_maildo |
| 62 | +new_email() |
| 63 | +|>from(@support_email) |
| 64 | +end |
| 65 | +end |