Closed 4refael closed 3 years ago
Yup. I am having the same issue.
Similar issue here, running mailcatcher
using Ruby 2.3.3 (x64) on Windows 10:
Exception: "\xC3" from ASCII-8BIT to UTF-8
Backtrace:
json (2.1.0) lib/json/common.rb:224:in `encode'
json (2.1.0) lib/json/common.rb:224:in `generate'
json (2.1.0) lib/json/common.rb:224:in `generate'
mailcatcher (0.6.5) lib/mail_catcher/web/application.rb:69:in `block (3 levels) in <class:Application>'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `block (3 levels) in push'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `each'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `block (2 levels) in push'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `each'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `block in push'
eventmachine (1.0.9.1) lib/eventmachine.rb:256:in `schedule'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `push'
mailcatcher (0.6.5) lib/mail_catcher/mail.rb:57:in `block in add_message'
eventmachine (1.0.9.1) lib/eventmachine.rb:981:in `block in run_deferred_callbacks'
eventmachine (1.0.9.1) lib/eventmachine.rb:978:in `times'
eventmachine (1.0.9.1) lib/eventmachine.rb:978:in `run_deferred_callbacks'
eventmachine (1.0.9.1) lib/eventmachine.rb:193:in `run_machine'
eventmachine (1.0.9.1) lib/eventmachine.rb:193:in `run'
mailcatcher (0.6.5) lib/mail_catcher.rb:173:in `run!'
mailcatcher (0.6.5) bin/mailcatcher:5:in `<top (required)>'
C:/Ruby23-x64/bin/mailcatcher:22:in `load'
C:/Ruby23-x64/bin/mailcatcher:22:in `<main>'
Same here on ruby 2.1.5p273 (2014-11-13) [x86_64-linux-gnu]
Exception: "\xC5" from ASCII-8BIT to UTF-8
Backtrace:
/usr/lib/ruby/2.1.0/json/common.rb:223:in `encode'
/usr/lib/ruby/2.1.0/json/common.rb:223:in `generate'
/usr/lib/ruby/2.1.0/json/common.rb:223:in `generate'
mailcatcher (0.6.5) lib/mail_catcher/web/application.rb:69:in `block (3 levels) in <class:Application>'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `call'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `block (3 levels) in push'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `each'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `block (2 levels) in push'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `each'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `block in push'
eventmachine (1.0.9.1) lib/eventmachine.rb:256:in `call'
eventmachine (1.0.9.1) lib/eventmachine.rb:256:in `schedule'
eventmachine (1.0.9.1) lib/em/channel.rb:43:in `push'
mailcatcher (0.6.5) lib/mail_catcher/mail.rb:57:in `block in add_message'
eventmachine (1.0.9.1) lib/eventmachine.rb:981:in `call'
eventmachine (1.0.9.1) lib/eventmachine.rb:981:in `block in run_deferred_callbacks'
eventmachine (1.0.9.1) lib/eventmachine.rb:978:in `times'
eventmachine (1.0.9.1) lib/eventmachine.rb:978:in `run_deferred_callbacks'
eventmachine (1.0.9.1) lib/eventmachine.rb:193:in `run_machine'
eventmachine (1.0.9.1) lib/eventmachine.rb:193:in `run'
mailcatcher (0.6.5) lib/mail_catcher.rb:173:in `run!'
mailcatcher (0.6.5) bin/mailcatcher:5:in `<top (required)>'
/usr/local/bin/mailcatcher:23:in `load'
/usr/local/bin/mailcatcher:23:in `<main>'
Please submit this as an issue at http://github.com/sj26/mailcatcher/issues
I think it is bug of mail sender, not mailcatcher. see https://github.com/sj26/mailcatcher/issues/322
I use UTF-8 in from, like the following code in ActionMailer::Base
:
default from: 'leão - my latin america brand <no-reply@leao.com.br>'
I did the following commit only to show a possible fix https://github.com/cerdiogenes/mailcatcher/commit/b2520fff2f2e53079818847877a2227f924a1c19
What do you think about it @sj26? If you think it's acceptable I can prepare a PR.
Best regards!
I think receiving mails with 8bit is root of problems. Because SMTP server of mailcatcher does not respond with 8BITMIME to the EHLO command, it should reject mail with 8bit from bad mail clients. I think sane mail clients re-send mail with 7bit encoding. It can help to reduce mail clients that violate RFCs.
@znz my email body is encoded with 7bit (I don't do anything special to have it, ActionMailer already send it ok), but the from header field keeps giving error, this is my from header:
From: =?UTF-8?Q?AlfaCon_-_AlfaCon_Concursos_P=C3=BAblicos_<no-reply@alf?=
=?UTF-8?Q?a-dev.com.br:3000>?=
The body have the proper charset and encoding:
Content-Type: multipart/mixed;
boundary="--==_mimepart_5b61a61b9d9a5_159c2b07c5d3d950208f3";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5b61a61b9d9a5_159c2b07c5d3d950208f3
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
And in the body I have this string <p>Obrigado por comprar no AlfaCon Concursos P=C3=BAblicos</p>
If I remove the accent from the from header
I get no exception and mailcatcher show the email properly.
So, my question is basically how I can use accents in from field?
I'm not a ruby dev, but I believe this is related. Using mailcatcher in a vagrant box that serves as a magento development server. If email contains some non-ascii characters (german umlauts, euro symbol), it doesn't get sent. Apache error log:
/var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:2032:in `match': invalid byte sequence in US-ASCII (ArgumentError)
from /var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:2032:in `match'
from /var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:2032:in `set_envelope_header'
from /var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:2132:in `init_with_string'
from /var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/message.rb:137:in `initialize'
from /var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/mail.rb:51:in `new'
from /var/lib/gems/2.5.0/gems/mail-2.7.1/lib/mail/mail.rb:51:in `new'
from /var/lib/gems/2.5.0/gems/mailcatcher-0.7.1/bin/catchmail:59:in `<top (required)>'
from /usr/local/bin/catchmail:23:in `load'
from /usr/local/bin/catchmail:23:in `<main>
So match function's argument is US-ASCII encoded, which is weird. Ruby / encoding related stuff:
vagrant@syone:~$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
vagrant@syone:~$ ruby -e 'p Encoding.default_external'
#<Encoding:UTF-8>
vagrant@syone:~$ locale
LANG=C.UTF-8
LANGUAGE=
LC_CTYPE="C.UTF-8"
LC_NUMERIC=C.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="C.UTF-8"
LC_MONETARY=C.UTF-8
LC_MESSAGES="C.UTF-8"
LC_PAPER=C.UTF-8
LC_NAME=C.UTF-8
LC_ADDRESS=C.UTF-8
LC_TELEPHONE=C.UTF-8
LC_MEASUREMENT=C.UTF-8
LC_IDENTIFICATION=C.UTF-8
LC_ALL=
But if I print out Encoding.default_external
from catchmail
, it really uses US-ASCII. Setting Encoding.default_external = en_US.UTF-8
within catchmail
solves the problem, also changing line 59 within catchmail
to message = Mail.new($stdin.read.force_encoding('UTF-8'))
solves it.
So I ended up changing sendmail_path within php.ini to:
sendmail_path = "LANG=en_US.UTF-8 /usr/bin/env catchmail -f vagrant@syone"
That works, but I still don't understand why catchmail thinks external encoding is US-ASCII.
MailCatcher does not advertise itself as 8-bit capable, and so mail clients should be sending mail in ascii compatible encodings. A feature request for 8 bit transfer encodings is now here, please follow if you're interested: #445