zendesk-ar_mailer 1.4.5 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +15 -5
- data/Rakefile +1 -1
- data/lib/action_mailer/ar_mailer.rb +2 -2
- data/lib/action_mailer/ar_sendmail.rb +15 -3
- data/lib/ar_sendmail_logger.rb +9 -0
- data/test/action_mailer.rb +4 -3
- data/test/test_armailer.rb +3 -1
- data/test/test_arsendmail.rb +32 -12
- metadata +2 -1
data/README.txt
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
= ar_mailer
|
2
2
|
|
3
|
-
A two-phase delivery agent for ActionMailer
|
3
|
+
A two-phase delivery agent for ActionMailer.
|
4
|
+
|
5
|
+
This fork allows you to add some context to the ar_mailer log, i.e. you can track "lost emails" such that when a customer complains of a missing email, you are able to find out what "identifier" in your system became what SMTP message-id, and continue tracking to the SMTP server logs.
|
6
|
+
|
7
|
+
This fork also logs in its own log file rather than using the Rails logger.
|
8
|
+
|
9
|
+
This fork is based on the fork by adzap (http://github.com/adzap/ar_mailer/tree/master) and includes the connectivity patches from gefilte (http://github.com/gefilte/ar_mailer/tree/master)
|
4
10
|
|
5
11
|
Rubyforge Project:
|
6
12
|
|
@@ -34,7 +40,7 @@ First, if you haven't already
|
|
34
40
|
|
35
41
|
Then
|
36
42
|
|
37
|
-
$ sudo gem install
|
43
|
+
$ sudo gem install zendesk-ar_mailer
|
38
44
|
|
39
45
|
See ActionMailer::ARMailer for instructions on converting to ARMailer.
|
40
46
|
|
@@ -43,7 +49,7 @@ See ar_sendmail -h for options to ar_sendmail.
|
|
43
49
|
NOTE: You may need to delete an smtp_tls.rb file if you have one lying
|
44
50
|
around. ar_mailer supplies it own.
|
45
51
|
|
46
|
-
=== Getting context aware logging
|
52
|
+
=== Getting context aware logging (this fork)
|
47
53
|
|
48
54
|
If you want to log some extra information that you can use to tie a specific send email to
|
49
55
|
something in your application, do this:
|
@@ -54,9 +60,11 @@ something in your application, do this:
|
|
54
60
|
|
55
61
|
2. Set the information you want ar_sendmail to log alongside the message-id in your mailer class:
|
56
62
|
|
57
|
-
headers(
|
63
|
+
headers('X-Delivery-Context' => 'Hello there')
|
58
64
|
|
59
|
-
This will print 'Hello there' in the line that also contains the message-id of the sent email
|
65
|
+
This will print 'Hello there' in the line that also contains the message-id of the sent email, like so:
|
66
|
+
|
67
|
+
ar_sendmail Fri Oct 17 12:04:58 +0000 2008: sent email 00000579421 [Hello there] from someone@somewhere.com to someone.else@somewhere.else.com: "250 OK id=1Kqo4g-0006Nx-MP\n"
|
60
68
|
|
61
69
|
=== init.d/rc.d scripts
|
62
70
|
|
@@ -68,3 +76,5 @@ the config file /etc/ar_sendmail.conf in place before starting.
|
|
68
76
|
|
69
77
|
For FreeBSD or NetBSD script is share/bsd/ar_sendmail. This is old and does not
|
70
78
|
support the config file unless someone wants to submit a patch.
|
79
|
+
|
80
|
+
Alternatively, use a monitoring solution like monit or god, or google: cron @reboot
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ ar_mailer_gemspec = Gem::Specification.new do |s|
|
|
18
18
|
s.email = %q{drbrain@segment7.net}
|
19
19
|
s.executables = ["ar_sendmail"]
|
20
20
|
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.txt"]
|
21
|
-
s.files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/ar_sendmail", "lib/action_mailer/ar_mailer.rb", "lib/action_mailer/ar_sendmail.rb", "lib/smtp_tls.rb", "share/bsd/ar_sendmail", "share/linux/ar_sendmail", "share/linux/ar_sendmail.conf", "test/action_mailer.rb", "test/test_armailer.rb", "test/test_arsendmail.rb"]
|
21
|
+
s.files = ["History.txt", "LICENSE.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/ar_sendmail", "lib/action_mailer/ar_mailer.rb", "lib/action_mailer/ar_sendmail.rb", "lib/ar_sendmail_logger.rb", "lib/smtp_tls.rb", "share/bsd/ar_sendmail", "share/linux/ar_sendmail", "share/linux/ar_sendmail.conf", "test/action_mailer.rb", "test/test_armailer.rb", "test/test_arsendmail.rb"]
|
22
22
|
s.has_rdoc = true
|
23
23
|
s.homepage = %q{http://seattlerb.org/ar_mailer}
|
24
24
|
s.rdoc_options = ["--main", "README.txt"]
|
@@ -96,10 +96,10 @@ class ActionMailer::ARMailer < ActionMailer::Base
|
|
96
96
|
def perform_delivery_activerecord(mail)
|
97
97
|
mail.destinations.each do |destination|
|
98
98
|
# If the email has the context header set, assume that the caller added a context column
|
99
|
-
if @@context_header && mail.
|
99
|
+
if @@context_header && mail.header_string(@@context_header)
|
100
100
|
@@email_class.create(
|
101
101
|
:mail => mail.encoded, :to => destination,
|
102
|
-
:from => mail.from.first, :context => mail
|
102
|
+
:from => mail.from.first, :context => mail.header_string(@@context_header)
|
103
103
|
)
|
104
104
|
else
|
105
105
|
@@email_class.create(:mail => mail.encoded, :to => destination, :from => mail.from.first)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
require 'net/smtp'
|
3
3
|
require 'smtp_tls'
|
4
|
+
require 'ar_sendmail_logger'
|
4
5
|
require 'rubygems'
|
5
6
|
|
6
7
|
class Object # :nodoc:
|
@@ -54,7 +55,7 @@ class ActionMailer::ARSendmail
|
|
54
55
|
##
|
55
56
|
# The version of ActionMailer::ARSendmail you are running.
|
56
57
|
|
57
|
-
VERSION = '1.4.
|
58
|
+
VERSION = '1.4.6'
|
58
59
|
|
59
60
|
##
|
60
61
|
# Maximum number of times authentication will be consecutively retried
|
@@ -85,6 +86,8 @@ class ActionMailer::ARSendmail
|
|
85
86
|
# ActiveRecord class that holds emails
|
86
87
|
|
87
88
|
attr_reader :email_class
|
89
|
+
|
90
|
+
attr_reader :logger
|
88
91
|
|
89
92
|
##
|
90
93
|
# True if only one delivery attempt will be made per call to run
|
@@ -201,6 +204,7 @@ end
|
|
201
204
|
options[:RailsEnv] = ENV['RAILS_ENV']
|
202
205
|
options[:TableName] = 'Email'
|
203
206
|
options[:Pidfile] = options[:Chdir] + '/log/ar_sendmail.pid'
|
207
|
+
options[:LogFile] = nil
|
204
208
|
|
205
209
|
opts = OptionParser.new do |opts|
|
206
210
|
opts.banner = "Usage: #{name} [options]"
|
@@ -253,6 +257,12 @@ end
|
|
253
257
|
options[:Pidfile] = pidfile
|
254
258
|
end
|
255
259
|
|
260
|
+
opts.on("-l", "--logfile LOGFILE",
|
261
|
+
"Set the logfile location",
|
262
|
+
"Default: #{options[:Chdir]}#{options[:LogFile]}", String) do |logfile|
|
263
|
+
options[:LogFile] = logfile
|
264
|
+
end
|
265
|
+
|
256
266
|
opts.on( "--mailq",
|
257
267
|
"Display a list of emails waiting to be sent") do |mailq|
|
258
268
|
options[:MailQ] = true
|
@@ -417,6 +427,7 @@ end
|
|
417
427
|
@max_age = options[:MaxAge]
|
418
428
|
|
419
429
|
@failed_auth_count = 0
|
430
|
+
@logger = ArSendmailLogger.new(options[:LogFile] || options[:Chdir] + '/log/ar_sendmail.log')
|
420
431
|
end
|
421
432
|
|
422
433
|
##
|
@@ -449,7 +460,7 @@ end
|
|
449
460
|
begin
|
450
461
|
res = smtp.send_message email.mail, email.from, email.to
|
451
462
|
email.destroy
|
452
|
-
if email.respond_to?(:context)
|
463
|
+
if email.respond_to?(:context) && email.context.to_s != ''
|
453
464
|
log "sent email %011d [%s] from %s to %s: %p" % [email.id, email.context, email.from, email.to, res]
|
454
465
|
else
|
455
466
|
log "sent email %011d from %s to %s: %p" % [email.id, email.from, email.to, res]
|
@@ -519,8 +530,9 @@ end
|
|
519
530
|
# Logs +message+ if verbose
|
520
531
|
|
521
532
|
def log(message)
|
533
|
+
message = "ar_sendmail #{Time.now}: #{message}"
|
522
534
|
$stderr.puts message if @verbose
|
523
|
-
|
535
|
+
logger.info(message)
|
524
536
|
end
|
525
537
|
|
526
538
|
##
|
data/test/action_mailer.rb
CHANGED
@@ -105,7 +105,7 @@ class Email
|
|
105
105
|
|
106
106
|
START = Time.parse 'Thu Aug 10 2006 11:19:48'
|
107
107
|
|
108
|
-
attr_accessor :from, :to, :mail, :last_send_attempt, :created_on, :id
|
108
|
+
attr_accessor :from, :to, :mail, :last_send_attempt, :created_on, :id, :context
|
109
109
|
|
110
110
|
@records = []
|
111
111
|
@id = 0
|
@@ -114,7 +114,7 @@ class Email
|
|
114
114
|
|
115
115
|
def self.create(record)
|
116
116
|
record = new record[:from], record[:to], record[:mail],
|
117
|
-
record[:last_send_attempt]
|
117
|
+
record[:last_send_attempt], record[:context]
|
118
118
|
records << record
|
119
119
|
return record
|
120
120
|
end
|
@@ -147,13 +147,14 @@ class Email
|
|
147
147
|
records.clear
|
148
148
|
end
|
149
149
|
|
150
|
-
def initialize(from, to, mail, last_send_attempt = nil)
|
150
|
+
def initialize(from, to, mail, last_send_attempt = nil, context = nil)
|
151
151
|
@from = from
|
152
152
|
@to = to
|
153
153
|
@mail = mail
|
154
154
|
@id = self.class.id += 1
|
155
155
|
@created_on = START + @id
|
156
156
|
@last_send_attempt = last_send_attempt || 0
|
157
|
+
@context = context
|
157
158
|
end
|
158
159
|
|
159
160
|
def destroy
|
data/test/test_armailer.rb
CHANGED
@@ -12,7 +12,9 @@ class Mailer < ActionMailer::ARMailer
|
|
12
12
|
def @mail.encoded() 'email' end
|
13
13
|
def @mail.from() ['nobody@example.com'] end
|
14
14
|
def @mail.destinations() %w[user1@example.com user2@example.com] end
|
15
|
-
def @mail.
|
15
|
+
def @mail.header_string(header_name, default = nil)
|
16
|
+
default
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
data/test/test_arsendmail.rb
CHANGED
@@ -362,7 +362,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
362
362
|
end
|
363
363
|
|
364
364
|
assert_equal '', out
|
365
|
-
|
365
|
+
assert err.index("expired 1 emails from the queue\n")
|
366
366
|
assert_equal 2, Email.records.length
|
367
367
|
|
368
368
|
assert_equal [e1, e2], Email.records
|
@@ -383,6 +383,24 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
383
383
|
assert_equal 2, Email.records.length
|
384
384
|
end
|
385
385
|
|
386
|
+
def test_context
|
387
|
+
email = Email.create :mail => 'body', :to => 'to', :from => 'from', :context => 'lemon'
|
388
|
+
|
389
|
+
out, err = util_capture do
|
390
|
+
@sm.deliver [email]
|
391
|
+
end
|
392
|
+
|
393
|
+
assert err.index('[lemon]')
|
394
|
+
|
395
|
+
email = Email.create :mail => 'body', :to => 'to', :from => 'from', :context => ''
|
396
|
+
|
397
|
+
out, err = util_capture do
|
398
|
+
@sm.deliver [email]
|
399
|
+
end
|
400
|
+
|
401
|
+
assert !err.index('[]')
|
402
|
+
end
|
403
|
+
|
386
404
|
def test_deliver
|
387
405
|
email = Email.create :mail => 'body', :to => 'to', :from => 'from'
|
388
406
|
|
@@ -396,7 +414,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
396
414
|
assert_equal 0, Net::SMTP.reset_called, 'Reset connection on SyntaxError'
|
397
415
|
|
398
416
|
assert_equal '', out
|
399
|
-
|
417
|
+
assert err.index("sent email 00000000001 from from to to: \"queued\"\n")
|
400
418
|
end
|
401
419
|
|
402
420
|
def test_deliver_auth_error
|
@@ -422,7 +440,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
422
440
|
assert_equal [60], @sm.slept
|
423
441
|
|
424
442
|
assert_equal '', out
|
425
|
-
|
443
|
+
assert err.index("authentication error, retrying: try again\n")
|
426
444
|
end
|
427
445
|
|
428
446
|
def test_deliver_auth_error_recover
|
@@ -452,7 +470,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
452
470
|
end
|
453
471
|
|
454
472
|
assert_equal 2, @sm.failed_auth_count
|
455
|
-
|
473
|
+
assert err.index("authentication error, giving up: try again\n")
|
456
474
|
end
|
457
475
|
|
458
476
|
def test_deliver_no_auth_without_emails
|
@@ -490,7 +508,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
490
508
|
assert_equal 1, Net::SMTP.reset_called, 'Reset connection on SyntaxError'
|
491
509
|
|
492
510
|
assert_equal '', out
|
493
|
-
|
511
|
+
assert err.index("error sending email 1: \"try again\"(Net::SMTPSyntaxError):\n\tone\n\ttwo\n\tthree\n")
|
494
512
|
end
|
495
513
|
|
496
514
|
def test_deliver_5xx_error
|
@@ -513,7 +531,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
513
531
|
assert_equal 1, Net::SMTP.reset_called, 'Reset connection on SyntaxError'
|
514
532
|
|
515
533
|
assert_equal '', out
|
516
|
-
|
534
|
+
assert err.index("5xx error sending email 1, removing from queue: \"unknown recipient\"(Net::SMTPFatalError):\n\tone\n\ttwo\n\tthree\n")
|
517
535
|
end
|
518
536
|
|
519
537
|
def test_deliver_errno_epipe
|
@@ -560,7 +578,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
560
578
|
assert_equal [60], @sm.slept
|
561
579
|
|
562
580
|
assert_equal '', out
|
563
|
-
|
581
|
+
assert err.index("server too busy, sleeping 60 seconds\n")
|
564
582
|
end
|
565
583
|
|
566
584
|
def test_deliver_syntax_error
|
@@ -586,7 +604,9 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
586
604
|
assert_operator now, :<=, Email.records.first.last_send_attempt
|
587
605
|
|
588
606
|
assert_equal '', out
|
589
|
-
|
607
|
+
|
608
|
+
assert err.index("error sending email 1: \"blah blah blah\"(Net::SMTPSyntaxError):\n\tone\n\ttwo\n\tthree\n")
|
609
|
+
assert err.index("sent email 00000000002 from from to to: \"queued\"\n")
|
590
610
|
end
|
591
611
|
|
592
612
|
def test_deliver_timeout
|
@@ -610,7 +630,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
610
630
|
assert_equal 1, Net::SMTP.reset_called, 'Reset connection on Timeout'
|
611
631
|
|
612
632
|
assert_equal '', out
|
613
|
-
|
633
|
+
assert err.index("error sending email 1: \"timed out\"(Timeout::Error):\n\tone\n\ttwo\n\tthree\n")
|
614
634
|
end
|
615
635
|
|
616
636
|
def test_do_exit
|
@@ -621,7 +641,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
621
641
|
end
|
622
642
|
|
623
643
|
assert_equal '', out
|
624
|
-
|
644
|
+
assert err.index("caught signal, shutting down\n")
|
625
645
|
end
|
626
646
|
|
627
647
|
def test_log
|
@@ -629,7 +649,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
629
649
|
@sm.log 'hi'
|
630
650
|
end
|
631
651
|
|
632
|
-
|
652
|
+
assert err.index("hi\n")
|
633
653
|
end
|
634
654
|
|
635
655
|
def test_find_emails
|
@@ -655,7 +675,7 @@ Last send attempt: Thu Aug 10 11:40:05 %s 2006
|
|
655
675
|
assert_equal emails, found_emails
|
656
676
|
|
657
677
|
assert_equal '', out
|
658
|
-
|
678
|
+
assert err.index("found 3 emails to send\n")
|
659
679
|
end
|
660
680
|
|
661
681
|
def test_smtp_settings
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk-ar_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- bin/ar_sendmail
|
34
34
|
- lib/action_mailer/ar_mailer.rb
|
35
35
|
- lib/action_mailer/ar_sendmail.rb
|
36
|
+
- lib/ar_sendmail_logger.rb
|
36
37
|
- lib/smtp_tls.rb
|
37
38
|
- share/bsd/ar_sendmail
|
38
39
|
- share/linux/ar_sendmail
|