Overview
Features
Download
Documentation
Community
Add-Ons & Services

Poco::Net::MailMessage and UTF-8

Please post support and help requests here.

Poco::Net::MailMessage and UTF-8

Postby gerrard171717 » 02 Nov 2009, 15:26

Hi,

First of all - I've only recently come across POCO and started evaluating its capabilities for our product's needs, and it's a great framework you've got there.

I'm mostly interested in the SMTP related features, as our product is required to send email notifications at various points.
Since these emails might be multi-lingual, we're using UTF-8 encoding to represent the textual data.

If I understand correctly, in order to send UTF-8 SMTP messages, I should perform the following actions:

Code: Select all
MailMessage message;
message.setSender(sender);
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, recipient));
message.setSubject("SomeString");
std::string content;
content += "Some UTF8 String, might not be english\n";
message.addContent(new StringPartSource(content), MailMessage::ENCODING_BASE64);

SMTPClientSession session(mailhost);
session.login();
session.sendMessage(message);
session.close();


My questions are:

1. How can I get this direction to work? It seems not to work for non-English characters, when trying to view the sent email via MS Outlook (which actually tends to be pretty lenient towards the RFC, and still). How can I actually send messages in UTF-8 encoding using POCO?

2. I also tried using ENCODING_8BIT instead of ENCODING_BASE64, which didn't seem to make any difference as far as the outcome goes. UTF-8 is definitely an 8-bit encoding, so which is the correct road to take?

Code: Select all
message.addContent(new StringPartSource(content), MailMessage::ENCODING_8BIT);


3. I couldn't find a way to specify the subject in UTF-8. I saw in gmail that non-English subjects are often received as UTF-8 strings, like this:
Code: Select all
Subject: =?utf-8?B?MTEzMyA616nXmdeg15XXmSDXodeY15jXldehINeU15bXnteg15QuINeU15bX?=  =?utf-8?B?nteg16rXmg==?=
Is there a way to get POCO into encoding the subject line for me using base64, and append the apperantly required delimiters (?B? and ?= for example) ?

Thanks,
G.
gerrard171717
 
Posts: 1
Joined: 02 Nov 2009, 14:41

Re: Poco::Net::MailMessage and UTF-8

Postby guenter » 03 Nov 2009, 00:49

1. How can I get this direction to work? It seems not to work for non-English characters, when trying to view the sent email via MS Outlook (which actually tends to be pretty lenient towards the RFC, and still). How can I actually send messages in UTF-8 encoding using POCO?


Try adding a

message.setContentType("text/plain; charset="utf-8");

before or after calling addContent().

2. I also tried using ENCODING_8BIT instead of ENCODING_BASE64, which didn't seem to make any difference as far as the outcome goes. UTF-8 is definitely an 8-bit encoding, so which is the correct road to take?


8BIT will only work if your SMTP server supports 8 BIT encoding. Using ENCODING_BASE64 or ENCODING_QUOTED_PRINTABLE are safe alternatives.

Is there a way to get POCO into encoding the subject line for me using base64, and append the apperantly required delimiters (?B? and ?= for example) ?


1.3.6 (currently only available from SVN) contains MailMessage::encodeWord() which will allow you to encode header fields. Currently, only "Q" encoding (not "B") is supported, though.
guenter
 
Posts: 1119
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron