Class: SipoMailer::Mailer
- Inherits:
-
Object
- Object
- SipoMailer::Mailer
show all
- Defined in:
- lib/sipo_mailer/email.rb
Defined Under Namespace
Classes: DeliveryError, Response
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(to:, from:, subject:, attachment: nil) ⇒ Mailer
Returns a new instance of Mailer.
21
22
23
24
25
26
|
# File 'lib/sipo_mailer/email.rb', line 21
def initialize(to:, from:, subject:, attachment: nil)
@to = to
@from = from
@subject = subject
@attachment = attachment
end
|
Class Method Details
.send(to: '[email protected]', from: SipoMailer.config.yaml.dig(:email, :address), subject: 'ahoj', attachment: nil) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/sipo_mailer/email.rb', line 28
def self.send(to: '[email protected]',
from: SipoMailer.config.yaml.dig(:email, :address),
subject: 'ahoj',
attachment: nil)
email = new(to: to, from: from, subject: subject, attachment: attachment)
begin
response = email.send
Response.new(response)
rescue DeliveryError => e
p e
end
end
|
Instance Method Details
#email ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/sipo_mailer/email.rb', line 57
def email
email = Mail.new
email.to = @to
email.from = @from
email.subject = @subject
email.body = email_body
email.add_file(@attachment.path) if @attachment
email
end
|
#send ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/sipo_mailer/email.rb', line 41
def send
email.deliver!
rescue SocketError
print "\n\nChyba při posílání emailu: adresa " \
"#{Mail.delivery_method.settings[:address]} není dostupná.\n"
exit
rescue Net::SMTPAuthenticationError
print "\n\nChyba při posílání emailu: " \
"chybné přihlašovací údaje pro emailovou schránku.\n"
exit
rescue Net::OpenTimeout
print "\n\nChyba při posílání emailu: vypršel časový limit "\
"při spojení s emailovým serverem.\n"
exit
end
|