You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

email.rake 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. namespace :redmine do
  18. namespace :email do
  19. desc <<-END_DESC
  20. Read an email from standard input.
  21. See redmine:email:receive_imap for more options and examples.
  22. END_DESC
  23. task :read => :environment do
  24. Mailer.with_synched_deliveries do
  25. MailHandler.safe_receive(STDIN.read, MailHandler.extract_options_from_env(ENV))
  26. end
  27. end
  28. desc <<-END_DESC
  29. Read emails from an IMAP server.
  30. Available IMAP options:
  31. host=HOST IMAP server host (default: 127.0.0.1)
  32. port=PORT IMAP server port (default: 143)
  33. ssl=SSL Use SSL/TLS? (default: false)
  34. starttls=STARTTLS Use STARTTLS? (default: false)
  35. username=USERNAME IMAP account
  36. password=PASSWORD IMAP password
  37. folder=FOLDER IMAP folder to read (default: INBOX)
  38. Processed emails control options:
  39. move_on_success=MAILBOX move emails that were successfully received
  40. to MAILBOX instead of deleting them
  41. move_on_failure=MAILBOX move emails that were ignored to MAILBOX
  42. User and permissions options:
  43. unknown_user=ACTION how to handle emails from an unknown user
  44. ACTION can be one of the following values:
  45. ignore: email is ignored (default)
  46. accept: accept as anonymous user
  47. create: create a user account
  48. no_permission_check=1 disable permission checking when receiving
  49. the email
  50. no_account_notice=1 disable new user account notification
  51. no_notification=1 disable email notification to new user
  52. default_group=foo,bar adds created user to foo and bar groups
  53. Issue attributes control options:
  54. project=PROJECT identifier of the target project
  55. project_from_subaddress=ADDR
  56. select project from subaddress of ADDR found
  57. in To, Cc, Bcc headers
  58. status=STATUS name of the target status
  59. tracker=TRACKER name of the target tracker
  60. category=CATEGORY name of the target category
  61. priority=PRIORITY name of the target priority
  62. assigned_to=ASSIGNEE assignee (username or group name)
  63. fixed_version=VERSION name of the target version
  64. private create new issues as private
  65. allow_override=ATTRS allow email content to set attributes values
  66. ATTRS is a comma separated list of attributes
  67. or 'all' to allow all attributes to be overridable
  68. (see below for details)
  69. Overrides:
  70. ATTRS is a comma separated list of attributes among:
  71. * project, tracker, status, priority, category, assigned_to, fixed_version,
  72. start_date, due_date, estimated_hours, done_ratio
  73. * custom fields names with underscores instead of spaces (case insensitive)
  74. Example: allow_override=project,priority,my_custom_field
  75. If the project option is not set, project is overridable by default for
  76. emails that create new issues.
  77. You can use allow_override=all to allow all attributes to be overridable.
  78. Examples:
  79. # No project specified. Emails MUST contain the 'Project' keyword:
  80. rake redmine:email:receive_imap RAILS_ENV="production" \\
  81. host=imap.foo.bar username=redmine@example.net password=xxx
  82. # Fixed project and default tracker specified, but emails can override
  83. # both tracker and priority attributes:
  84. rake redmine:email:receive_imap RAILS_ENV="production" \\
  85. host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\
  86. project=foo \\
  87. tracker=bug \\
  88. allow_override=tracker,priority
  89. END_DESC
  90. task :receive_imap => :environment do
  91. imap_options = {:host => ENV['host'],
  92. :port => ENV['port'],
  93. :ssl => ENV['ssl'],
  94. :starttls => ENV['starttls'],
  95. :username => ENV['username'],
  96. :password => ENV['password'],
  97. :folder => ENV['folder'],
  98. :move_on_success => ENV['move_on_success'],
  99. :move_on_failure => ENV['move_on_failure']}
  100. Mailer.with_synched_deliveries do
  101. Redmine::IMAP.check(imap_options, MailHandler.extract_options_from_env(ENV))
  102. end
  103. end
  104. desc <<-END_DESC
  105. Read emails from an POP3 server.
  106. Available POP3 options:
  107. host=HOST POP3 server host (default: 127.0.0.1)
  108. port=PORT POP3 server port (default: 110)
  109. username=USERNAME POP3 account
  110. password=PASSWORD POP3 password
  111. apop=1 use APOP authentication (default: false)
  112. ssl=SSL Use SSL? (default: false)
  113. delete_unprocessed=1 delete messages that could not be processed
  114. successfully from the server (default
  115. behaviour is to leave them on the server)
  116. See redmine:email:receive_imap for more options and examples.
  117. END_DESC
  118. task :receive_pop3 => :environment do
  119. pop_options = {:host => ENV['host'],
  120. :port => ENV['port'],
  121. :apop => ENV['apop'],
  122. :ssl => ENV['ssl'],
  123. :username => ENV['username'],
  124. :password => ENV['password'],
  125. :delete_unprocessed => ENV['delete_unprocessed']}
  126. Mailer.with_synched_deliveries do
  127. Redmine::POP3.check(pop_options, MailHandler.extract_options_from_env(ENV))
  128. end
  129. end
  130. desc "Send a test email to the user with the provided login name"
  131. task :test, [:login] => :environment do |task, args|
  132. include Redmine::I18n
  133. abort l(:notice_email_error, "Please include the user login to test with. Example: rake redmine:email:test[login]") if args[:login].blank?
  134. user = User.find_by_login(args[:login])
  135. abort l(:notice_email_error, "User #{args[:login]} not found") unless user && user.logged?
  136. begin
  137. Mailer.deliver_test_email(user)
  138. puts l(:notice_email_sent, user.mail)
  139. rescue => e
  140. abort l(:notice_email_error, e.message)
  141. end
  142. end
  143. end
  144. end