[racket] Encoding problem when using smtp-send-message send email to evernote

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jan 29 10:48:32 EST 2015

The `smtp-send-message` and `standard-header` functions do not attempt
any encoding --- which means that it ends up encoding in UTF-8, while
the receiving end probably interprets it as Latin-1.

There's a `net/unihead` library that provides an `encode-for-header`
function that's suitable for encoding a subject line:

 > (encode-for-header "中文标题" )
 "=?UTF-8?B?5Lit5paH5qCH6aKY?="

Oddly, the `net/unihead` library appears to be undocumented; I'll fix
that.


Instead of encoding the content, you might be able to just add

  Content-Type: text/plain; charset=UTF-8

to the header of your message. If I remember correctly, that should
work as long as the receiver is happy with 8-bit mail content (which
seems to be the case from the information that you've provided).


At Thu, 29 Jan 2015 16:28:10 +0800, "fyooo" wrote:
> hi, all
> 
> 
> I have an encoding problem when using smtp-send-message send email to evernote.‍
> 
> 
> My code is:
> 
>> #lang racket
> 
> 
> (provide (all-defined-out))
> 
> 
> (require net/dns)
> (require net/head)
> (require net/smtp)
> (require openssl/mzssl)
> 
> 
> (require "options.rkt")
> 
> 
> (define (send-evernote entitle encontent)
>   (smtp-send-message
>    (dns-get-address (dns-find-nameserver) "smtp.qq.com")
>    "fyooo at foxmail.com"
>    (list EVERMAIL)
>    (standard-message-header
>     "Pentester <fyooo at foxmail.com>"
>     (list (string-append "fyooo <" EVERMAIL ">"))
>     '() ; CC
>     '() ; BCC
>     entitle)
>    (list encontent)
>    #:port-no 465
>    #:auth-user "fyooo"
>    #:auth-passwd E136PAS
>    #:tcp-connect ssl-connect))‍
> 
> 
> 
> The `EVERMAIL` and `E136PAS ‍` above is import from my config file 
> "options.rkt".
> 
> 
> EVERMAIL is my private evernote mail like `xxxx.yyyy at m.evernote.com‍`, I use it 
> to create new note from email.
> 
> 
> When I use this function as
> 
> 
> (send-evernote  "中文标题" "中文内容")‍
> 
> 
> The title of evernote would be `ä¸ææ é¢`, which is in wrong format.
> 
> 
> But the content would be  "中文内容", which is ok.‍‍
> 
> 
> I've try to using my web mail to send a Chinese email to my private Evernote 
> mail, the format is ok too.
> 
> 
> I don't know what's going on here.____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.