email encoding problem

瀏覽次數:114 次
跳到第一則未讀訊息

night_stalker

未讀,
2009年9月12日 清晨6:40:132009/9/12
收件者:Lift
hi all,

I'm new to lift, I met with a problem when trying to send a mail.

//Mail.scala---------------------------------------
package my.site
import net.liftweb.util._
import Helpers._
import Mailer._
import javax.mail._
import javax.mail.internet._
import xml._

object Mail {
var from = ""

def config(host: String, user: String, password: String) {
System.setProperty("mail.smtp.starttls.enable","true");
System.setProperty("mail.smtp.host", host)
System.setProperty("mail.smtp.auth", "true")
System.setProperty("mail.mime.charset", "UTF-8")
Mailer.authenticator = Full(new Authenticator {
override def getPasswordAuthentication =
new PasswordAuthentication(user, password)
})
from = user
}

def send(to: String, xmlContent: NodeSeq) {
sendMail(From(from), Subject("hi"),
XHTMLMailBodyType(xmlContent)::To(to)::Nil : _* )
}
}

//useMail.scala------------------------------------------
...
// host, user, password
my.site.Mail.config("smtp.gmail.com", "***@gmail.com", "*****")
// the recieved mail body becomes "<p>??</p>"
my.site.Mail.send("***@gmail.com", (<p>你好</p>))

All source files are UTF-8, and project.build.sourceEncoding is UTF-8
too.
Is there a missing step?

Indrajit Raychaudhuri

未讀,
2009年9月12日 上午10:34:492009/9/12
收件者:Lift
Can you please check what the Content-Type field in the mail header
looks like in the mail that you get?

Cheers, Indrajit
> my.site.Mail.config("smtp.gmail.com", "*...@gmail.com", "*****")
> // the recieved mail body becomes "<p>??</p>"
> my.site.Mail.send("*...@gmail.com", (<p>你好</p>))

night_stalker

未讀,
2009年9月12日 上午11:55:282009/9/12
收件者:Lift
the last part is like:

Subject: hi
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_0_21171036.1252770284921"

------=_Part_0_21171036.1252770284921
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<p>??</p>
------=_Part_0_21171036.1252770284921--

I don't know how to set Content-Type ...

On Sep 12, 10:34 pm, Indrajit Raychaudhuri <indraj...@gmail.com>
wrote:

Viktor Klang

未讀,
2009年9月12日 中午12:03:062009/9/12
收件者:lif...@googlegroups.com
Content-Type: text/html; charset=us-ascii

IMHO that should read:

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

So basically, the content-type isn't correctly set.
--
Viktor Klang

Blog: klangism.blogspot.com
Twttr: viktorklang

Lift Committer - liftweb.com
AKKA Committer - akkasource.org
Cassidy - github.com/viktorklang/Cassidy.git
SoftPub founder: http://groups.google.com/group/softpub

Indrajit Raychaudhuri

未讀,
2009年9月12日 中午12:17:542009/9/12
收件者:Lift
Indeed, but "Content-Transfer-Encoding: 7bit" could be the real
suspect.

I think, MimeBodyPart forces us-ascii charset for 7bit encoding.

Cheers, Indrajit

night_stalker

未讀,
2009年9月12日 中午12:54:522009/9/12
收件者:Lift
Thank you all for your replies.

I just modified net/liftweb/util/Mailer.scala,
replaced all "text/html" with "text/html;charset=UTF-8" , then
problem solved.

the result mail's Content-Type part becomes:

Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

and "你好" is shown correctly.

Viktor Klang

未讀,
2009年9月12日 中午12:56:192009/9/12
收件者:lif...@googlegroups.com

Good catch!

On Sep 12, 2009 6:18 PM, "Indrajit Raychaudhuri" <indr...@gmail.com> wrote:


Indeed, but "Content-Transfer-Encoding: 7bit" could be the real
suspect.

I think, MimeBodyPart forces us-ascii charset for 7bit encoding.

Cheers, Indrajit

On Sep 12, 9:03 pm, Viktor Klang <viktor.kl...@gmail.com> wrote: > Content-Type: text/html; charset...

> On Sat, Sep 12, 2009 at 5:55 PM, night_stalker <usur...@gmail.com> wrote: > > > the last part is l...

> Viktor Klang > > Blog: klangism.blogspot.com > Twttr: viktorklang > > Lift Committer - liftweb.com...

--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subs...

David Pollak

未讀,
2009年9月14日 晚上7:35:252009/9/14
收件者:lif...@googlegroups.com
On Sat, Sep 12, 2009 at 9:54 AM, night_stalker <usu...@gmail.com> wrote:

Thank you all for your replies.

I just modified  net/liftweb/util/Mailer.scala,
replaced all  "text/html"  with  "text/html;charset=UTF-8" , then
problem solved.

I'll check this in
 

the result mail's Content-Type part becomes:

 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable

and "你好" is shown correctly.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
回覆所有人
回覆作者
轉寄
0 則新訊息