2
votes

I spent over a week to build an auto ticket submission system based on Redmine (Bitnami 3.0.0), but there is one problem confused me a lot and I am struggling it till now.

Here is my background:

Need to build an auto ticket submission system and all tickets auto created via one email account.

Firstly, I create one Gmail account used for ticket creation email address, let's say it "[email protected]" and my company email address is "[email protected]". All tickets could be created automatically without an issue from [email protected] to [email protected]

[email protected] --> [email protected] --> ticket auto creation succeed (via [email protected] to create ticket)

However, to avoid secure issue, an company email account which named [email protected] needs to be used instead of the gmail one. [email protected] is a shared mailbox. Here are my test results.

[email protected] --> [email protected] --> ticket auto creation failed (via [email protected] to create ticket)

[email protected] --> [email protected] --> ticket auto creation failed (via [email protected] to create ticket)

[email protected] --> [email protected] --> ticket auto creation succeed (via [email protected] to create ticket)

What I can see from OWA webpage, if failed, all new emails had been gone through and "marked as read" and then left in the mail server.

Here is my command:

rake redmine:email:receive_imap unknown_user=accept no_permission_check=1 RAILS_ENV="production" host=imap.abc.com port=143 username=ticket password=xxx project=projectname allow_override=project,subject,status,tracker,priority,category,author,desc,issue --trace

However, there is no any error from the trace

C:\Bitnami\redmine-3.0.0-0\apps\redmine\htdocs>rake redmine:email:receive_imap unknown_user=accept no_permission_check=1 RAILS_ENV="production" host=imap.abc.com port=143 username=ticket password=xxx project=projectname allow_override=project,subject,status,tracker,priority,categ
ory,author,desc,issue --trace
DL is deprecated, please use Fiddle
** Invoke redmine:email:receive_imap (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute redmine:email:receive_imap

C:\Bitnami\redmine-3.0.0-0\apps\redmine\htdocs>\

A debug level has been turned on as well. But here is only I could find from the production.log, only I could see is "Message xx can not be processed", nothing more...

Receiving message xx  
  [1m[36mSetting Load (0.0ms)[0m  [1mSELECT  `settings`.* FROM `settings` WHERE `settings`.`name` = 'mail_from'  ORDER BY `settings`.`id` DESC LIMIT 1[0m
  [1m[35mUser Load (1.0ms)[0m  SELECT  DISTINCT `users`.* FROM `users` INNER JOIN `email_addresses` ON `email_addresses`.`user_id` = `users`.`id` WHERE `users`.`type` IN ('User', 'AnonymousUser') AND (LOWER(address) IN ('[email protected]'))  ORDER BY `users`.`id` ASC LIMIT 1
Message xx can not be processed

Then, I checked C:\Bitnami\redmine-3.0.0-0\apps\redmine\htdocs\lib\redmine\imap.rb

  if MailHandler.safe_receive(msg, options)
    logger.debug "Message #{uid} successfully received" if logger && logger.debug?
    if imap_options[:move_on_success]
      imap.uid_copy(uid, imap_options[:move_on_success])
    end
    imap.uid_store(uid, "+FLAGS", [:Seen, :Deleted])
  else
    logger.debug "Message #{uid} can not be processed" if logger && logger.debug?
    imap.uid_store(uid, "+FLAGS", [:Seen])
    if imap_options[:move_on_failure]
      imap.uid_copy(uid, imap_options[:move_on_failure])
      imap.uid_store(uid, "+FLAGS", [:Deleted])
    end
  end

Everytime, if mails sent between company email addresses, the MailHandler.safe_receive(msg, options)is false. But if mails sent from gmail to company email address, this is true.

I really have no idea what cause it happen and is it the issue from my company mailbox configurations? My company is using Exchange Server.

Is there any way could solve this issue or any work around? Thank you so much!

=============

Additional: I find out the reason caused this issue is because my Email Content-Type is "text/html", if "text/plain", no any issue.

Below are my new findings:

But it looks like Redmine supports HTML Only email and I have no idea why my email cannot be processed.

Here is the code snippet from "mail_handler.rb"

parts = if (text_parts = email.all_parts.select {|p| p.mime_type == 'text/plain'}).present?
          text_parts
        elsif (html_parts = email.all_parts.select {|p| p.mime_type == 'text/html'}).present?
          html_parts
        else
          [email]
        end

parts.reject! do |part|
  part.attachment?
end

@plain_text_body = parts.map do |p|
  body_charset = Mail::RubyVer.respond_to?(:pick_encoding) ?
                   Mail::RubyVer.pick_encoding(p.charset).to_s : p.charset
  Redmine::CodesetUtil.to_utf8(p.body.decoded, body_charset)
end.join("\r\n")

# strip html tags and remove doctype directive
if parts.any? {|p| p.mime_type == 'text/html'}
  @plain_text_body = strip_tags(@plain_text_body.strip)
  @plain_text_body.sub! %r{^<!DOCTYPE .*$}, ''
end

Even though my email is "Content-Type: text/html; charset=us-ascii", it still cannot be processed. Tested by Outlook 2010

Is there anyone has the similar issue or solution for that? thank you!

1
I'm also using the bitnami ubuntu VM with Redmine 3.0.0. I try to fetch (IMAP, but POP3 makes no difference) incoming emails from our ticket adress from an exchange server and it only worked when the emails were sent by an iphone. From different external email accounts or using the same account with Outlook instead sending from Iphone it didn't work. Thanks to your research, I tested to send plain-text emails with Outlook to the exchange and it works. I also tested to fetch from my private mailserver and it works without problems. So it seems that exchange is doing sth. wrong or different. - edditor
Could you find sth. out in the meantime? I still don't have a solution for my problem. - edditor

1 Answers

1
votes

I had the same problem and was focused many days on Redmine without finding any solution.

Finally, I decided to look at my Exchange Online parameters and modified my IMAP email account used for Redmine.

Here is the link to connect to your Exchange Online with Powershell: http://community.office365.com/en-us/f/158/t/158857.aspx

Of course, if you don't use this Exchange release, you should be able to access to it directly.

Here is the line to execute in Powershell to convert emails to plain text instead of default HTML:

Set-CASMailbox [email protected] -ImapMessagesRetrievalMimeFormat TextOnly -imapUseProtocolDefaults $false

Then you can check the result with the following line:

get-casmailbox [email protected] | format-list imap*

I hope it will help you to solve your problem!