You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by la...@teliasonera.com on 2016/03/23 11:20:56 UTC

Problems with encoding UTF-8 for åäö

Hi
I have a problem that some mail clients show the wrong encoding for Swedish characters (åäö). I try setting the message encoding to UTF-8 but it did't work i most have forgot something in the code.
If you see any anything wrong in the code.



Java code:
----------------------------------
header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8"); 
client = new SMTPClient("UTF-8");
client.connect(server);

client.login();

client.setSender(sender);
client.addRecipient(recipient);

for (String recpt : ccList) {
	client.addRecipient(recpt);
}

writer = client.sendMessageData();

if (writer != null) {
	writer.write(header.toString());
	writer.write(body);
	writer.close();
	client.completePendingCommand();
}

client.logout();
client.disconnect();


Raw message in Thunderbird using source view: 
----------------------------------------------------------------------------------------
Content-Type: text/plain; charset="UTF-8"

Subject: äåö
....
X-STA-Spam: subject:?????? ?????? spec:disguised to:2**0 header:To:1
X-BTI-AntiSpam: score:0,sta:7/030,dnsbl:off,sw:off,bsn:none,spf:off,bsctr:off,dk:off,pbmf:none,ipr:0/3,trusted:yes,ts:no,bs:no,ubl:off
Received-SPF: none
....
MIME-Version: 1.0


åäö

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Problems with encoding UTF-8 for åäö

Posted by Mark Fortner <ph...@gmail.com>.
What happens if you use 'utf-8' - all lowercase?

Mark
On Mar 23, 2016 6:23 AM, "Christopher Schultz" <ch...@christopherschultz.net>
wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Lars,
>
> On 3/23/16 9:10 AM, lars.z.carlsson@teliasonera.com wrote:
> > I switch to iso-8859-1 and now everything works fine thanks for the
> > help
>
> That's the first time I've ever heard anyone say that.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iEYEARECAAYFAlbymKcACgkQ9CaO5/Lv0PBXNgCfdjTJjY8J/naQkhTSF5zQk012
> 2OkAn3rGOrp1+im2EEdD0OJmClz4vdvE
> =zzsg
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: Problems with encoding UTF-8 for åäö

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lars,

On 3/23/16 9:10 AM, lars.z.carlsson@teliasonera.com wrote:
> I switch to iso-8859-1 and now everything works fine thanks for the
> help

That's the first time I've ever heard anyone say that.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlbymKcACgkQ9CaO5/Lv0PBXNgCfdjTJjY8J/naQkhTSF5zQk012
2OkAn3rGOrp1+im2EEdD0OJmClz4vdvE
=zzsg
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: Problems with encoding UTF-8 for åäö

Posted by la...@teliasonera.com.
Hi
I switch to iso-8859-1 and now everything works fine thanks for the help 

btw i use 
            <dependency>
				<groupId>commons-net</groupId>
				<artifactId>commons-net</artifactId>
				<version>3.4</version>
			</dependency>

---
Lars Carlsson
Phone: +46702507901
________________________________________
From: sebb [sebbaz@gmail.com]
Sent: Wednesday, March 23, 2016 12:35 PM
To: Commons Users List
Subject: Re: Problems with encoding UTF-8 for åäö

Nor have you specified which Commons component you are using.

There are at least two that can be used to send e-mails.

On 23 March 2016 at 11:23, Maria Jimena Sanchez <ji...@gmail.com> wrote:
> Are you using the correct UTF-8 symbol? We still can't see how you assign
> content to the subject variable
>
> On Wed, Mar 23, 2016, 8:17 AM <la...@teliasonera.com> wrote:
>
>> Hi
>> I have the problem on Hotmail.com i attach the complete method.
>>
>>
>>         private void sendEmail(String sender, String recipient, String
>> subject,
>>                         String body) throws IOException {
>>                 String server;
>>                 List<String> ccList = new ArrayList<String>();
>>                 Writer writer;
>>                 SimpleSMTPHeader header;
>>                 SMTPClient client;
>>
>>                 header = new SimpleSMTPHeader(sender, recipient, subject);
>>                 header.addHeaderField("Content-Type", "text/plain;
>> charset=" + "UTF-8");
>>                 client = new SMTPClient("UTF-8");
>>                 client.connect(server);
>>
>>                 client.login();
>>
>>                 client.setSender(sender);
>>                 client.addRecipient(recipient);
>>
>>                 for (String recpt : ccList) {
>>                         client.addRecipient(recpt);
>>                 }
>>
>>                 writer = client.sendMessageData();
>>
>>                 if (writer != null) {
>>                         writer.write(header.toString());
>>                         writer.write(body);
>>                         writer.close();
>>                         client.completePendingCommand();
>>                 }
>>
>>                 client.logout();
>>                 client.disconnect();
>>         }
>>
>>
>> ---
>> Lars Carlsson
>> Phone: +46702507901
>> ________________________________________
>> From: sebb [sebbaz@gmail.com]
>> Sent: Wednesday, March 23, 2016 11:39 AM
>> To: Commons Users List
>> Subject: Re: Problems with encoding UTF-8 for åäö
>>
>> On 23 March 2016 at 10:20,  <la...@teliasonera.com> wrote:
>> > Hi
>>
>> What software are you having a problem with?
>> This list applies to multiple components.
>>
>> > I have a problem that some mail clients show the wrong encoding for
>> Swedish characters (åäö). I try setting the message encoding to UTF-8 but
>> it did't work i most have forgot something in the code.
>> > If you see any anything wrong in the code.
>>
>> The code does not show how the subject variable is created.
>>
>> >
>> >
>> > Java code:
>> > ----------------------------------
>> > header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8");
>> > client = new SMTPClient("UTF-8");
>> > client.connect(server);
>> >
>> > client.login();
>> >
>> > client.setSender(sender);
>> > client.addRecipient(recipient);
>> >
>> > for (String recpt : ccList) {
>> >         client.addRecipient(recpt);
>> > }
>> >
>> > writer = client.sendMessageData();
>> >
>> > if (writer != null) {
>> >         writer.write(header.toString());
>> >         writer.write(body);
>> >         writer.close();
>> >         client.completePendingCommand();
>> > }
>> >
>> > client.logout();
>> > client.disconnect();
>> >
>> >
>> > Raw message in Thunderbird using source view:
>> >
>> ----------------------------------------------------------------------------------------
>> > Content-Type: text/plain; charset="UTF-8"
>> >
>> > Subject: äåö
>> > ....
>> > X-STA-Spam: subject:?????? ?????? spec:disguised to:2**0 header:To:1
>> > X-BTI-AntiSpam:
>> score:0,sta:7/030,dnsbl:off,sw:off,bsn:none,spf:off,bsctr:off,dk:off,pbmf:none,ipr:0/3,trusted:yes,ts:no,bs:no,ubl:off
>> > Received-SPF: none
>> > ....
>> > MIME-Version: 1.0
>> >
>> >
>> > åäö
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> > For additional commands, e-mail: user-help@commons.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Problems with encoding UTF-8 for åäö

Posted by sebb <se...@gmail.com>.
Nor have you specified which Commons component you are using.

There are at least two that can be used to send e-mails.

On 23 March 2016 at 11:23, Maria Jimena Sanchez <ji...@gmail.com> wrote:
> Are you using the correct UTF-8 symbol? We still can't see how you assign
> content to the subject variable
>
> On Wed, Mar 23, 2016, 8:17 AM <la...@teliasonera.com> wrote:
>
>> Hi
>> I have the problem on Hotmail.com i attach the complete method.
>>
>>
>>         private void sendEmail(String sender, String recipient, String
>> subject,
>>                         String body) throws IOException {
>>                 String server;
>>                 List<String> ccList = new ArrayList<String>();
>>                 Writer writer;
>>                 SimpleSMTPHeader header;
>>                 SMTPClient client;
>>
>>                 header = new SimpleSMTPHeader(sender, recipient, subject);
>>                 header.addHeaderField("Content-Type", "text/plain;
>> charset=" + "UTF-8");
>>                 client = new SMTPClient("UTF-8");
>>                 client.connect(server);
>>
>>                 client.login();
>>
>>                 client.setSender(sender);
>>                 client.addRecipient(recipient);
>>
>>                 for (String recpt : ccList) {
>>                         client.addRecipient(recpt);
>>                 }
>>
>>                 writer = client.sendMessageData();
>>
>>                 if (writer != null) {
>>                         writer.write(header.toString());
>>                         writer.write(body);
>>                         writer.close();
>>                         client.completePendingCommand();
>>                 }
>>
>>                 client.logout();
>>                 client.disconnect();
>>         }
>>
>>
>> ---
>> Lars Carlsson
>> Phone: +46702507901
>> ________________________________________
>> From: sebb [sebbaz@gmail.com]
>> Sent: Wednesday, March 23, 2016 11:39 AM
>> To: Commons Users List
>> Subject: Re: Problems with encoding UTF-8 for åäö
>>
>> On 23 March 2016 at 10:20,  <la...@teliasonera.com> wrote:
>> > Hi
>>
>> What software are you having a problem with?
>> This list applies to multiple components.
>>
>> > I have a problem that some mail clients show the wrong encoding for
>> Swedish characters (åäö). I try setting the message encoding to UTF-8 but
>> it did't work i most have forgot something in the code.
>> > If you see any anything wrong in the code.
>>
>> The code does not show how the subject variable is created.
>>
>> >
>> >
>> > Java code:
>> > ----------------------------------
>> > header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8");
>> > client = new SMTPClient("UTF-8");
>> > client.connect(server);
>> >
>> > client.login();
>> >
>> > client.setSender(sender);
>> > client.addRecipient(recipient);
>> >
>> > for (String recpt : ccList) {
>> >         client.addRecipient(recpt);
>> > }
>> >
>> > writer = client.sendMessageData();
>> >
>> > if (writer != null) {
>> >         writer.write(header.toString());
>> >         writer.write(body);
>> >         writer.close();
>> >         client.completePendingCommand();
>> > }
>> >
>> > client.logout();
>> > client.disconnect();
>> >
>> >
>> > Raw message in Thunderbird using source view:
>> >
>> ----------------------------------------------------------------------------------------
>> > Content-Type: text/plain; charset="UTF-8"
>> >
>> > Subject: äåö
>> > ....
>> > X-STA-Spam: subject:?????? ?????? spec:disguised to:2**0 header:To:1
>> > X-BTI-AntiSpam:
>> score:0,sta:7/030,dnsbl:off,sw:off,bsn:none,spf:off,bsctr:off,dk:off,pbmf:none,ipr:0/3,trusted:yes,ts:no,bs:no,ubl:off
>> > Received-SPF: none
>> > ....
>> > MIME-Version: 1.0
>> >
>> >
>> > åäö
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> > For additional commands, e-mail: user-help@commons.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Problems with encoding UTF-8 for åäö

Posted by Maria Jimena Sanchez <ji...@gmail.com>.
Are you using the correct UTF-8 symbol? We still can't see how you assign
content to the subject variable

On Wed, Mar 23, 2016, 8:17 AM <la...@teliasonera.com> wrote:

> Hi
> I have the problem on Hotmail.com i attach the complete method.
>
>
>         private void sendEmail(String sender, String recipient, String
> subject,
>                         String body) throws IOException {
>                 String server;
>                 List<String> ccList = new ArrayList<String>();
>                 Writer writer;
>                 SimpleSMTPHeader header;
>                 SMTPClient client;
>
>                 header = new SimpleSMTPHeader(sender, recipient, subject);
>                 header.addHeaderField("Content-Type", "text/plain;
> charset=" + "UTF-8");
>                 client = new SMTPClient("UTF-8");
>                 client.connect(server);
>
>                 client.login();
>
>                 client.setSender(sender);
>                 client.addRecipient(recipient);
>
>                 for (String recpt : ccList) {
>                         client.addRecipient(recpt);
>                 }
>
>                 writer = client.sendMessageData();
>
>                 if (writer != null) {
>                         writer.write(header.toString());
>                         writer.write(body);
>                         writer.close();
>                         client.completePendingCommand();
>                 }
>
>                 client.logout();
>                 client.disconnect();
>         }
>
>
> ---
> Lars Carlsson
> Phone: +46702507901
> ________________________________________
> From: sebb [sebbaz@gmail.com]
> Sent: Wednesday, March 23, 2016 11:39 AM
> To: Commons Users List
> Subject: Re: Problems with encoding UTF-8 for åäö
>
> On 23 March 2016 at 10:20,  <la...@teliasonera.com> wrote:
> > Hi
>
> What software are you having a problem with?
> This list applies to multiple components.
>
> > I have a problem that some mail clients show the wrong encoding for
> Swedish characters (åäö). I try setting the message encoding to UTF-8 but
> it did't work i most have forgot something in the code.
> > If you see any anything wrong in the code.
>
> The code does not show how the subject variable is created.
>
> >
> >
> > Java code:
> > ----------------------------------
> > header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8");
> > client = new SMTPClient("UTF-8");
> > client.connect(server);
> >
> > client.login();
> >
> > client.setSender(sender);
> > client.addRecipient(recipient);
> >
> > for (String recpt : ccList) {
> >         client.addRecipient(recpt);
> > }
> >
> > writer = client.sendMessageData();
> >
> > if (writer != null) {
> >         writer.write(header.toString());
> >         writer.write(body);
> >         writer.close();
> >         client.completePendingCommand();
> > }
> >
> > client.logout();
> > client.disconnect();
> >
> >
> > Raw message in Thunderbird using source view:
> >
> ----------------------------------------------------------------------------------------
> > Content-Type: text/plain; charset="UTF-8"
> >
> > Subject: äåö
> > ....
> > X-STA-Spam: subject:?????? ?????? spec:disguised to:2**0 header:To:1
> > X-BTI-AntiSpam:
> score:0,sta:7/030,dnsbl:off,sw:off,bsn:none,spf:off,bsctr:off,dk:off,pbmf:none,ipr:0/3,trusted:yes,ts:no,bs:no,ubl:off
> > Received-SPF: none
> > ....
> > MIME-Version: 1.0
> >
> >
> > åäö
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

RE: Problems with encoding UTF-8 for åäö

Posted by la...@teliasonera.com.
Hi
I have the problem on Hotmail.com i attach the complete method.


	private void sendEmail(String sender, String recipient, String subject,
			String body) throws IOException {
		String server;
		List<String> ccList = new ArrayList<String>();
		Writer writer;
		SimpleSMTPHeader header;
		SMTPClient client;

		header = new SimpleSMTPHeader(sender, recipient, subject);
		header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8"); 
		client = new SMTPClient("UTF-8");
		client.connect(server);

		client.login();

		client.setSender(sender);
		client.addRecipient(recipient);

		for (String recpt : ccList) {
			client.addRecipient(recpt);
		}

		writer = client.sendMessageData();

		if (writer != null) {
			writer.write(header.toString());
			writer.write(body);
			writer.close();
			client.completePendingCommand();
		}

		client.logout();
		client.disconnect();
	}


---
Lars Carlsson
Phone: +46702507901
________________________________________
From: sebb [sebbaz@gmail.com]
Sent: Wednesday, March 23, 2016 11:39 AM
To: Commons Users List
Subject: Re: Problems with encoding UTF-8 for åäö

On 23 March 2016 at 10:20,  <la...@teliasonera.com> wrote:
> Hi

What software are you having a problem with?
This list applies to multiple components.

> I have a problem that some mail clients show the wrong encoding for Swedish characters (åäö). I try setting the message encoding to UTF-8 but it did't work i most have forgot something in the code.
> If you see any anything wrong in the code.

The code does not show how the subject variable is created.

>
>
> Java code:
> ----------------------------------
> header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8");
> client = new SMTPClient("UTF-8");
> client.connect(server);
>
> client.login();
>
> client.setSender(sender);
> client.addRecipient(recipient);
>
> for (String recpt : ccList) {
>         client.addRecipient(recpt);
> }
>
> writer = client.sendMessageData();
>
> if (writer != null) {
>         writer.write(header.toString());
>         writer.write(body);
>         writer.close();
>         client.completePendingCommand();
> }
>
> client.logout();
> client.disconnect();
>
>
> Raw message in Thunderbird using source view:
> ----------------------------------------------------------------------------------------
> Content-Type: text/plain; charset="UTF-8"
>
> Subject: äåö
> ....
> X-STA-Spam: subject:?????? ?????? spec:disguised to:2**0 header:To:1
> X-BTI-AntiSpam: score:0,sta:7/030,dnsbl:off,sw:off,bsn:none,spf:off,bsctr:off,dk:off,pbmf:none,ipr:0/3,trusted:yes,ts:no,bs:no,ubl:off
> Received-SPF: none
> ....
> MIME-Version: 1.0
>
>
> åäö
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Problems with encoding UTF-8 for åäö

Posted by sebb <se...@gmail.com>.
On 23 March 2016 at 10:20,  <la...@teliasonera.com> wrote:
> Hi

What software are you having a problem with?
This list applies to multiple components.

> I have a problem that some mail clients show the wrong encoding for Swedish characters (åäö). I try setting the message encoding to UTF-8 but it did't work i most have forgot something in the code.
> If you see any anything wrong in the code.

The code does not show how the subject variable is created.

>
>
> Java code:
> ----------------------------------
> header.addHeaderField("Content-Type", "text/plain; charset=" + "UTF-8");
> client = new SMTPClient("UTF-8");
> client.connect(server);
>
> client.login();
>
> client.setSender(sender);
> client.addRecipient(recipient);
>
> for (String recpt : ccList) {
>         client.addRecipient(recpt);
> }
>
> writer = client.sendMessageData();
>
> if (writer != null) {
>         writer.write(header.toString());
>         writer.write(body);
>         writer.close();
>         client.completePendingCommand();
> }
>
> client.logout();
> client.disconnect();
>
>
> Raw message in Thunderbird using source view:
> ----------------------------------------------------------------------------------------
> Content-Type: text/plain; charset="UTF-8"
>
> Subject: äåö
> ....
> X-STA-Spam: subject:?????? ?????? spec:disguised to:2**0 header:To:1
> X-BTI-AntiSpam: score:0,sta:7/030,dnsbl:off,sw:off,bsn:none,spf:off,bsctr:off,dk:off,pbmf:none,ipr:0/3,trusted:yes,ts:no,bs:no,ubl:off
> Received-SPF: none
> ....
> MIME-Version: 1.0
>
>
> åäö
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org