Smalltalk Pharo ZdcSecureSMTPClient not showing ht

2019-05-03 11:20发布

问题:

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