Smalltalk Pharo ZdcSecureSMTPClient not showing html formatting in GMail?

ⅰ亾dé卋堺 提交于 2019-12-22 08:52:11

问题


I'm using ZdcSecureSMTPClient to send an html formatted string to a gmail account. But when I send it it displays the html encoding as plain text. ie)

mailMessage := MailMessage empty.
mailMessage setField: 'subject' toString: 'Trying to send html '.
mailMessage body: (MIMEDocument contentType: 'text/html\n' 
                content:  '<html><head><b>  Dear   </b></head></html>' 

This shows is Gmail as: 'html> head> Dear /b>/head>/html>'

Using Seaside/Pharo 2.0 one click image.


回答1:


What you use to set the mime type is not what is expected (additionally, the content of the message should be in body, not head). Use something like the following:

mailMessage := MailMessage empty.
mailMessage setField: 'subject' toString: 'Trying to send html '.
mailMessage addMixedPart: '<html><head></head><body><i>  Dear</i>   </body></html>' contentType: ZnMimeType textHtml printString.

ZdcSecureSMTPClient sendUsingGMailAccount: 'you@gmail.com' password: 'XXXXXXX' to: 'recipient@server.com' message: mailMessage.

You can check that your message is correct by sending the message text to your message object.




回答2:


Thanks everyone for the swift and quick answers. I found the solution to be adding the alternative part the message as below:

mailMessage := MailMessage empty. mailMessage setField: 'from' toString: from. mailMessage setField: 'to' toString: to. mailMessage setField: 'subject' toString: subject. mailMessage addAlternativePart: textBody contents contentType: 'text/plain'. mailMessage addAlternativePart: htmlBody contents contentType: 'text/html'.

the link is: http://forum.world.st/Re-Seaside-dev-Accessing-service-from-a-mail-td4671547.html#a4672088



来源:https://stackoverflow.com/questions/19508544/smalltalk-pharo-zdcsecuresmtpclient-not-showing-html-formatting-in-gmail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!