Class: Easyemail
- Inherits:
-
Object
- Object
- Easyemail
- Defined in:
- lib/mailer.rb,
lib/easyemail.rb,
lib/easyemail/version.rb
Defined Under Namespace
Classes: Mailer
Constant Summary collapse
- VERSION =
"1.0.0"- @@config =
YAML.load_file(File.dirname(__FILE__) + "/easyemail/smtp.yml")
Instance Attribute Summary collapse
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #email(subject, content) ⇒ Object
- #load_smtp_settings_from_yaml(path) ⇒ Object
- #smtp_settings(smtp) ⇒ Object
- #support ⇒ Object
Instance Attribute Details
#to ⇒ Object
Returns the value of attribute to.
7 8 9 |
# File 'lib/easyemail.rb', line 7 def to @to end |
Instance Method Details
#email(subject, content) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/easyemail.rb', line 54 def email subject, content # content支持html if @config && @to if @to.respond_to? :each @to.each do | e | Mailer.send_email(@from, e, subject, content).deliver end else Mailer.send_email(@from, @to, subject, content).deliver end else raise "check smtp_settings and receiver!" end end |
#load_smtp_settings_from_yaml(path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/easyemail.rb', line 25 def load_smtp_settings_from_yaml path smtp = YAML.load_file(path) if smtp["provider"] # 如果指定了邮件服务商 就直接跳转到该服务商 # 待选列表 163, hhu, qq, gmail self.send("smtp_settings_for_#{smtp["provider"]}", smtp["user_name"], smtp["password"]) else self.smtp_settings smtp end end |
#smtp_settings(smtp) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/easyemail.rb', line 36 def smtp_settings smtp # common settings for smtp, all provided by user. begin ActionMailer::Base.smtp_settings = { address: smtp['address'], port: smtp["port"], authentication: smtp["authentication"], user_name: smtp['user_name'], password: smtp['password'], enable_starttls_auto: smtp["enable_starttls_auto"] } @from = smtp["user_name"] @config = true rescue raise "wrong parameters for smtp settings." end end |
#support ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/easyemail.rb', line 69 def support ret = [] @@config.each do | key, value | ret.push key end ret end |