##// END OF EJS Templates
Use async email deliveries in rake tasks (#16784)....
Jean-Philippe Lang -
r12848:2d3f3cd9aa45
parent child
Show More
@@ -1,174 +1,180
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 namespace :redmine do
19 19 namespace :email do
20 20
21 21 desc <<-END_DESC
22 22 Read an email from standard input.
23 23
24 24 General options:
25 25 unknown_user=ACTION how to handle emails from an unknown user
26 26 ACTION can be one of the following values:
27 27 ignore: email is ignored (default)
28 28 accept: accept as anonymous user
29 29 create: create a user account
30 30 no_permission_check=1 disable permission checking when receiving
31 31 the email
32 32 no_account_notice=1 disable new user account notification
33 33 default_group=foo,bar adds created user to foo and bar groups
34 34
35 35 Issue attributes control options:
36 36 project=PROJECT identifier of the target project
37 37 status=STATUS name of the target status
38 38 tracker=TRACKER name of the target tracker
39 39 category=CATEGORY name of the target category
40 40 priority=PRIORITY name of the target priority
41 41 allow_override=ATTRS allow email content to override attributes
42 42 specified by previous options
43 43 ATTRS is a comma separated list of attributes
44 44
45 45 Examples:
46 46 # No project specified. Emails MUST contain the 'Project' keyword:
47 47 rake redmine:email:read RAILS_ENV="production" < raw_email
48 48
49 49 # Fixed project and default tracker specified, but emails can override
50 50 # both tracker and priority attributes:
51 51 rake redmine:email:read RAILS_ENV="production" \\
52 52 project=foo \\
53 53 tracker=bug \\
54 54 allow_override=tracker,priority < raw_email
55 55 END_DESC
56 56
57 57 task :read => :environment do
58 Mailer.with_synched_deliveries do
58 59 MailHandler.receive(STDIN.read, MailHandler.extract_options_from_env(ENV))
59 60 end
61 end
60 62
61 63 desc <<-END_DESC
62 64 Read emails from an IMAP server.
63 65
64 66 General options:
65 67 unknown_user=ACTION how to handle emails from an unknown user
66 68 ACTION can be one of the following values:
67 69 ignore: email is ignored (default)
68 70 accept: accept as anonymous user
69 71 create: create a user account
70 72 no_permission_check=1 disable permission checking when receiving
71 73 the email
72 74 no_account_notice=1 disable new user account notification
73 75 default_group=foo,bar adds created user to foo and bar groups
74 76
75 77 Available IMAP options:
76 78 host=HOST IMAP server host (default: 127.0.0.1)
77 79 port=PORT IMAP server port (default: 143)
78 80 ssl=SSL Use SSL? (default: false)
79 81 username=USERNAME IMAP account
80 82 password=PASSWORD IMAP password
81 83 folder=FOLDER IMAP folder to read (default: INBOX)
82 84
83 85 Issue attributes control options:
84 86 project=PROJECT identifier of the target project
85 87 status=STATUS name of the target status
86 88 tracker=TRACKER name of the target tracker
87 89 category=CATEGORY name of the target category
88 90 priority=PRIORITY name of the target priority
89 91 allow_override=ATTRS allow email content to override attributes
90 92 specified by previous options
91 93 ATTRS is a comma separated list of attributes
92 94
93 95 Processed emails control options:
94 96 move_on_success=MAILBOX move emails that were successfully received
95 97 to MAILBOX instead of deleting them
96 98 move_on_failure=MAILBOX move emails that were ignored to MAILBOX
97 99
98 100 Examples:
99 101 # No project specified. Emails MUST contain the 'Project' keyword:
100 102
101 103 rake redmine:email:receive_imap RAILS_ENV="production" \\
102 104 host=imap.foo.bar username=redmine@example.net password=xxx
103 105
104 106
105 107 # Fixed project and default tracker specified, but emails can override
106 108 # both tracker and priority attributes:
107 109
108 110 rake redmine:email:receive_imap RAILS_ENV="production" \\
109 111 host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
110 112 project=foo \\
111 113 tracker=bug \\
112 114 allow_override=tracker,priority
113 115 END_DESC
114 116
115 117 task :receive_imap => :environment do
116 118 imap_options = {:host => ENV['host'],
117 119 :port => ENV['port'],
118 120 :ssl => ENV['ssl'],
119 121 :username => ENV['username'],
120 122 :password => ENV['password'],
121 123 :folder => ENV['folder'],
122 124 :move_on_success => ENV['move_on_success'],
123 125 :move_on_failure => ENV['move_on_failure']}
124 126
127 Mailer.with_synched_deliveries do
125 128 Redmine::IMAP.check(imap_options, MailHandler.extract_options_from_env(ENV))
126 129 end
130 end
127 131
128 132 desc <<-END_DESC
129 133 Read emails from an POP3 server.
130 134
131 135 Available POP3 options:
132 136 host=HOST POP3 server host (default: 127.0.0.1)
133 137 port=PORT POP3 server port (default: 110)
134 138 username=USERNAME POP3 account
135 139 password=PASSWORD POP3 password
136 140 apop=1 use APOP authentication (default: false)
137 141 delete_unprocessed=1 delete messages that could not be processed
138 142 successfully from the server (default
139 143 behaviour is to leave them on the server)
140 144
141 145 See redmine:email:receive_imap for more options and examples.
142 146 END_DESC
143 147
144 148 task :receive_pop3 => :environment do
145 149 pop_options = {:host => ENV['host'],
146 150 :port => ENV['port'],
147 151 :apop => ENV['apop'],
148 152 :username => ENV['username'],
149 153 :password => ENV['password'],
150 154 :delete_unprocessed => ENV['delete_unprocessed']}
151 155
156 Mailer.with_synched_deliveries do
152 157 Redmine::POP3.check(pop_options, MailHandler.extract_options_from_env(ENV))
153 158 end
159 end
154 160
155 161 desc "Send a test email to the user with the provided login name"
156 162 task :test, [:login] => :environment do |task, args|
157 163 include Redmine::I18n
158 164 abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank?
159 165
160 166 user = User.find_by_login(args[:login])
161 167 abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged?
162 168
163 169 ActionMailer::Base.raise_delivery_errors = true
164 170 begin
165 171 Mailer.with_synched_deliveries do
166 172 Mailer.test_email(user).deliver
167 173 end
168 174 puts l(:notice_email_sent, user.mail)
169 175 rescue Exception => e
170 176 abort l(:notice_email_error, e.message)
171 177 end
172 178 end
173 179 end
174 180 end
General Comments 0
You need to be logged in to leave comments. Login now