10

When I want to send an email I composed in Emacs, I press C-c C-c and am always presented with such an error message:

These default coding systems were tried to encode text
in the buffer `2015-02-03_19:08:30_1':
  (utf-8-unix (302 . 4194243) (303 . 4194208) (305 . 4194243) (306 .
  4194217) (308 . 4194243) (309 . 4194221) (311 . 4194243) (312 .
  4194227))
However, each of them encountered characters it couldn't encode:
  utf-8-unix cannot encode these:        

Click on a character (or switch to this window by `M-o'
and select the characters by RET) to jump to the place it appears,
where `C-u M-x what-cursor-position' will give information about it.
[...]

At this point I can manually select an encoding and my email is sent. What I don't understand is that I always select utf-8 as the encoding when I receive this message and it just works! But the message said that utf-8-unix can't encode some characters.

Can somebody tell me why Emacs can't select utf-8 by default and what this error message mean in this context?

EDIT 2015/02/05

I'm using mu4e and I tried (setq-default buffer-file-coding-system 'utf-8) without success (after evaluating this expression, if I start writing a new email, the variable's value is not 'utf-8 but 'utf-8-unix).

EDIT 2015/02/06

I also tried M-x set-keyboard-coding-system utf-8 and (setq mm-coding-system-priorities '(utf-8)) but this had no visible effect.

EDIT 2015/02/21

I've just noticed this problem only happens if smtpmail-queue-mail is t. So I guess the problem is in the email queueing feature.

Damien Cassou
  • 877
  • 4
  • 14
  • Does the incantation to prefer `utf-8` in all buffers help? `(setq-default buffer-file-coding-system 'utf-8)` – PythonNut Feb 03 '15 at 23:34
  • Which mailer are you using? RMAIL, Gnus, Wanderlust? – jch Feb 03 '15 at 23:56
  • @jch It's tagged `mu4e`. – PythonNut Feb 04 '15 at 01:20
  • I answered by editing the question – Damien Cassou Feb 05 '15 at 09:47
  • can the setting `(set-keyboard-coding-system 'utf-8)` help? – Name Feb 05 '15 at 15:34
  • It doesn't help (I updated the question again) – Damien Cassou Feb 06 '15 at 20:32
  • I had a similar problem, not with `mu4e` but with `eshell` see http://emacs.stackexchange.com/q/7162/2609. My guess is that if you remove something in a directory equivalent to `~\.eshell\` (like `~\.mu4e\` `~.mu4e`) the problem will probably solve. Warning I don't have `mu4e` on my system so my suggestion may not work. – Name Feb 21 '15 at 17:18
  • BTW what is after `However, each of them encountered characters it couldn't encode: utf-8-unix cannot encode these:` ? which characters causes the inconvenience? – Name Feb 21 '15 at 17:19
  • My smtpmail-queue-mail variable evaluates to nil but I still have this problem. – Angus Lee Mar 25 '16 at 04:05
  • @DamienCassou, I have the same problem, tried many things, nothing helps, hugely annoying. Here is a related GitHub issue: https://github.com/djcb/mu/issues/1081 Please consider adding your information. – tmalsburg Sep 20 '17 at 10:05
  • As of http://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-26&id=aca5f0072b531d9621b0ff90e656e589281c8155 this is hopefully fixed. – stsquad Oct 09 '17 at 13:55

3 Answers3

4

I have dealt with this issue a lot. The encoding will be depending on information in the file. If there is no information in the file explicitly to determine what it is, you could get such things as above.

If your work doesn't involve a lot of ancient systems which require different coding, you could consider to force default UTF-8 coding everywhere. It’s practically a standard nowadays, at least in the West (for me anyway), as it is dominant on the Web; has a one-to-one mapping with ASCII; flexible enough to represent any unicode character in the world. But in order to make Emacs use UTF-8 everywhere by default:

(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment 'utf-8)

Once evaluated, Emacs will treat new files, buffers, processes, and so on as though they are UTF-8. Keep in mind Emacs will still use a different coding system if the file has a file-local variable like this -*- coding: euc-tw -*- near the top of the file. (Check 48.2.4 Local Variables in Files in the Emacs manual.)

Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
EHartC
  • 169
  • 1
  • 4
  • I have added these lines to .emacs. However, if I create a new TeX file, "file -bi" still reports that it is encoded as us-ascii. Any ideas? – painfulenglish Feb 07 '16 at 17:16
0

I use Emacs built-in compose-mail (C-x m) to send email and encountered similar issue on encoding. I don't sure if this would help you:

(setq mm-coding-system-priorities '(utf-8))
kuanyui
  • 1,020
  • 6
  • 16
-1

With all the settings above the encoding windows continued to show up. I did more investigation and I found out that setting:

(setq message-default-charset 'utf-8)
(add-to-list 'mm-body-charset-encoding-alist '(utf-8 . base64))

Solved the issue for me. I'm working on Mac OS 10.14.5, Emacs 26.1.

Navidot
  • 732
  • 5
  • 12
  • Why this answer is downvoted? As I said it solved the problem for me, and I just wanted to share. – Navidot Jan 15 '21 at 17:29