JavaMail - posielanie mailov v cestine

2009-11-30 Thread Dusan Zatkovsky
Ahoj.

Zapasim so $SUBJ a zacinam byt znacne strateny.

Potrebujem poslat email pomocou java mail z windows, ktory ma v sebe cesky 
text a attachment. Uz sa s tym lamem 2 hodiny a nemozem tomu prist na klb.

Kod:

MimeBodyPart text_part = new MimeBodyPart();
text_part.setText(message_text);
text_part.setHeader("Content-Type", "text/plain; charset=\"" + 
System.getProperty("file.encoding") + "\"");
text_part.setHeader("Content-Transfer-Encoding", "quoted-printable");

Nasledne to posielam ako multipart s attachmentom.
Vysledkom je, ze thunderbird to zobrazi ok, cokolvek ine (outlook) zle.

Uryvok na disk ulozeneho multipart:

Return-Path: 
Delivered-To: t...@test.cz
Received: (qmail 5290 invoked by uid 89); 30 Nov 2009 11:49:43 -
Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
  s=private; d=test.cz;
  b=YCY6ijt89eDlbCYX5hlSsXNTtBiPYnBECNPYxwcWN8Lv/+SvW7MAsx6YmGH0H406;
Received: from unknown (HELO xpprim) (dusan.zatkov...@test.cz@93.185.97.186)
  by server1.test.cz with ESMTPA; 30 Nov 2009 11:49:43 -
Date: Mon, 30 Nov 2009 12:49:43 +0100 (CET)
From: f...@test.cz
To: t...@test.cz
Message-ID: <28848200.5.1259581783779.javamail.ad...@xpprim>
Subject: =?Cp1250?Q?Zpr=E1v=E1_z_datov=E9_schr=E1nky_do_vlastn=EDch_ru?=
 =?Cp1250?Q?kou_od_test,_s.r.o.,78501_=8Aternberk,_CZ?=
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=_Part_3_8979901.1259581783639"

--=_Part_3_8979901.1259581783639
Content-Type: text/plain; charset="Cp1250"
Content-Transfer-Encoding: quoted-printable

Dne 09.10.2009 11:56:05 V=E1m byla doru=E8ena nov=E1 datov=E1 zpr=E1va s ID=
 101737.
-- CUT --
--=_Part_3_8979901.1259581783639
Content-Type: application/octet-stream; name=message.zfo
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=message.zfo

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAaCAJIAEggPoPHE6
TWVzc2FnZURvd25sb2FkUmVzcG9uc2UgeG1sbnM6cT0iaHR0cDovL2lzZHMuY3plY2hwb2ludC5j
-- CUT --


Subject je dobre ( cesky ), telo uz nie. Skusal som rozne kombinacie charset a 
transfer encoding, vzdy to bolo zle.

Bol by niekto taky dobry a pastol mi sem example s fungujucou cestinou? 
Copy-pastol som asi 3 example z webu a ani jeden nezafungoval.

Diky.


-- 
Dusan


... tykajte mi


Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Radovana Straube
Zdravim,

ja nastavujem kodovanie v mailoch nasledovne:
mbp.setText(message_text, "ISO-8859-1");
Ty asi budes potrebovat ISO-8859-2.
Mam to ale vyskusane len v nemcine :-(

S pozdravom
Radovana Straube


--- On Mon, 11/30/09, Dusan Zatkovsky  wrote:

> From: Dusan Zatkovsky 
> Subject: JavaMail - posielanie mailov v cestine
> To: "Java" 
> Date: Monday, November 30, 2009, 1:00 PM
> Ahoj.
> 
> Zapasim so $SUBJ a zacinam byt znacne strateny.
> 
> Potrebujem poslat email pomocou java mail z windows, ktory
> ma v sebe cesky 
> text a attachment. Uz sa s tym lamem 2 hodiny a nemozem
> tomu prist na klb.
> 
> Kod:
> 
> MimeBodyPart text_part = new MimeBodyPart();
> text_part.setText(message_text);
> text_part.setHeader("Content-Type", "text/plain;
> charset=\"" + 
> System.getProperty("file.encoding") + "\"");
> text_part.setHeader("Content-Transfer-Encoding",
> "quoted-printable");
> 
> Nasledne to posielam ako multipart s attachmentom.
> Vysledkom je, ze thunderbird to zobrazi ok, cokolvek ine
> (outlook) zle.
> 
> Uryvok na disk ulozeneho multipart:
> 
> Return-Path: 
> Delivered-To: t...@test.cz
> Received: (qmail 5290 invoked by uid 89); 30 Nov 2009
> 11:49:43 -
> Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
>   s=private; d=test.cz;
>  
> b=YCY6ijt89eDlbCYX5hlSsXNTtBiPYnBECNPYxwcWN8Lv/+SvW7MAsx6YmGH0H406;
> Received: from unknown (HELO xpprim) (dusan.zatkov...@test.cz@93.185.97.186)
>   by server1.test.cz with ESMTPA; 30 Nov 2009 11:49:43
> -
> Date: Mon, 30 Nov 2009 12:49:43 +0100 (CET)
> From: f...@test.cz
> To: t...@test.cz
> Message-ID:
> <28848200.5.1259581783779.javamail.ad...@xpprim>
> Subject:
> =?Cp1250?Q?Zpr=E1v=E1_z_datov=E9_schr=E1nky_do_vlastn=EDch_ru?=
>  =?Cp1250?Q?kou_od_test,_s.r.o.,78501_=8Aternberk,_CZ?=
> MIME-Version: 1.0
> Content-Type: multipart/mixed;
> boundary="=_Part_3_8979901.1259581783639"
> 
> --=_Part_3_8979901.1259581783639
> Content-Type: text/plain; charset="Cp1250"
> Content-Transfer-Encoding: quoted-printable
> 
> Dne 09.10.2009 11:56:05 V=E1m byla doru=E8ena nov=E1
> datov=E1 zpr=E1va s ID=
>  101737.
> -- CUT --
> --=_Part_3_8979901.1259581783639
> Content-Type: application/octet-stream; name=message.zfo
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename=message.zfo
> 
> MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAaCAJIAEggPoPHE6
> TWVzc2FnZURvd25sb2FkUmVzcG9uc2UgeG1sbnM6cT0iaHR0cDovL2lzZHMuY3plY2hwb2ludC5j
> -- CUT --
> 
> 
> Subject je dobre ( cesky ), telo uz nie. Skusal som rozne
> kombinacie charset a 
> transfer encoding, vzdy to bolo zle.
> 
> Bol by niekto taky dobry a pastol mi sem example s
> fungujucou cestinou? 
> Copy-pastol som asi 3 example z webu a ani jeden
> nezafungoval.
> 
> Diky.
> 
> 
> -- 
> Dusan
> 
> 
> ... tykajte mi
> 





Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Kamil Podlesak
setText nastavuje i hlavicku, takze setHeader je potom zbytecne.
Dale pouziti file.encoding je chyba, protoze javovske identifikatory
obecne nejsou shodne s temi standardnimi, takze emal clienti nemusi
"Cp1250" rozpoznat (pokud vubec takove obskurni nestandardni kodovani
zna). Nastesti mame unicode, takze neni nutne si s tim nejak zvlast
lamat hlavu.

Asi takto:

MimeBodyPart text_part = new MimeBodyPart();
text_part.setText(message_text, "UTF-8");
text_part.setHeader("Content-Transfer-Encoding", "quoted-printable");


Kamil Podlesak

2009/11/30 Dusan Zatkovsky :
> Ahoj.
>
> Zapasim so $SUBJ a zacinam byt znacne strateny.
>
> Potrebujem poslat email pomocou java mail z windows, ktory ma v sebe cesky
> text a attachment. Uz sa s tym lamem 2 hodiny a nemozem tomu prist na klb.
>
> Kod:
>
> MimeBodyPart text_part = new MimeBodyPart();
> text_part.setText(message_text);
> text_part.setHeader("Content-Type", "text/plain; charset=\"" +
> System.getProperty("file.encoding") + "\"");
> text_part.setHeader("Content-Transfer-Encoding", "quoted-printable");
>
> Nasledne to posielam ako multipart s attachmentom.
> Vysledkom je, ze thunderbird to zobrazi ok, cokolvek ine (outlook) zle.
>
> Uryvok na disk ulozeneho multipart:
>
> Return-Path: 
> Delivered-To: t...@test.cz
> Received: (qmail 5290 invoked by uid 89); 30 Nov 2009 11:49:43 -
> Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
>  s=private; d=test.cz;
>  b=YCY6ijt89eDlbCYX5hlSsXNTtBiPYnBECNPYxwcWN8Lv/+SvW7MAsx6YmGH0H406;
> Received: from unknown (HELO xpprim) (dusan.zatkov...@test.cz@93.185.97.186)
>  by server1.test.cz with ESMTPA; 30 Nov 2009 11:49:43 -
> Date: Mon, 30 Nov 2009 12:49:43 +0100 (CET)
> From: f...@test.cz
> To: t...@test.cz
> Message-ID: <28848200.5.1259581783779.javamail.ad...@xpprim>
> Subject: =?Cp1250?Q?Zpr=E1v=E1_z_datov=E9_schr=E1nky_do_vlastn=EDch_ru?=
>  =?Cp1250?Q?kou_od_test,_s.r.o.,78501_=8Aternberk,_CZ?=
> MIME-Version: 1.0
> Content-Type: multipart/mixed; boundary="=_Part_3_8979901.1259581783639"
>
> --=_Part_3_8979901.1259581783639
> Content-Type: text/plain; charset="Cp1250"
> Content-Transfer-Encoding: quoted-printable
>
> Dne 09.10.2009 11:56:05 V=E1m byla doru=E8ena nov=E1 datov=E1 zpr=E1va s ID=
>  101737.
> -- CUT --
> --=_Part_3_8979901.1259581783639
> Content-Type: application/octet-stream; name=message.zfo
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename=message.zfo
>
> MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAaCAJIAEggPoPHE6
> TWVzc2FnZURvd25sb2FkUmVzcG9uc2UgeG1sbnM6cT0iaHR0cDovL2lzZHMuY3plY2hwb2ludC5j
> -- CUT --
>
>
> Subject je dobre ( cesky ), telo uz nie. Skusal som rozne kombinacie charset a
> transfer encoding, vzdy to bolo zle.
>
> Bol by niekto taky dobry a pastol mi sem example s fungujucou cestinou?
> Copy-pastol som asi 3 example z webu a ani jeden nezafungoval.
>
> Diky.
>
>
> --
> Dusan
>
>
> ... tykajte mi
>


Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Dusan Zatkovsky
Ahoj.

> Asi takto:
>
> MimeBodyPart text_part = new MimeBodyPart();
> text_part.setText(message_text, "UTF-8");
> text_part.setHeader("Content-Transfer-Encoding", "quoted-printable");
>

No a presne takto mi to nefunguje. Teraz si nie som 100% isty, ci v tomto 
pripade je zle len subject, alebo aj body.

-- 
Dusan


... tykajte mi


Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Josef Cacek
Ahojte,

On Mon, Nov 30, 2009 at 1:00 PM, Dusan Zatkovsky  wrote:
> Zapasim so $SUBJ a zacinam byt znacne strateny.
>
> Potrebujem poslat email pomocou java mail z windows, ktory ma v sebe cesky
> text a attachment. Uz sa s tym lamem 2 hodiny a nemozem tomu prist na klb.

zkoušel jsi metodu MimeBodyPart.setContent(aStr, aContentType) ?
Nám pracuje následující postup bez problémů:

public static void sendSmtpMessage(String aHost, String aFrom, String
aTo, String aCharset, String aSubject,
String aText) throws AddressException, MessagingException,
UnsupportedEncodingException {
Properties tmpProps = new Properties();
tmpProps.setProperty("mail.transport.protocol", "smtp");
tmpProps.setProperty("mail.smtp.host", aHost);
tmpProps.setProperty("mail.from", aFrom);
Session session = Session.getDefaultInstance(tmpProps);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(aFrom));
message.setFrom(new InternetAddress(aFrom));
MimeMultipart multipart = new MimeMultipart();
message.setRecipients(RecipientType.TO, InternetAddress.parse(aTo, 
false));
MimeBodyPart tmpBP = new MimeBodyPart();
tmpBP.setContent(aText, "text/plain; charset=" + aCharset);
multipart.addBodyPart(tmpBP);
message.setSubject(MimeUtility.encodeText(aSubject, aCharset, null));
message.setContent(multipart);
message.setSentDate(new Date());
Transport.send(message);
}

public static void testSend(String aCharset) {
try {
sendSmtpMessage("localhost", "josef.ca...@gmail.com",
"t...@cacek.cz", aCharset,
"příliš žluťoučký kůň úpěl ďábelské ódy", 
"PŘÍLIŠ ŽLUŤOUČKÝ KŮŇ
ÚPĚL ĎÁBELSKÉ ÓDY");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String[] args) {
testSend("utf-8");
testSend("iso-8859-2");
testSend("windows-1250");
}

-- pepa cacek


Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Vladimir Naprstek
Posílám kus kódu z mé app. posílá to ale v html a včetně příloh (takové
jsem měl zadání). Snad se v tom dá vyznat...

// Create a message part to represent the body
text
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(bodyInHTML,
"text/html; charset=UTF-8"); //$NON-NLS-1$
Multipart multipart = new MimeMultipart();
// add the message body to the mime message
multipart.addBodyPart(messageBodyPart);

// append attachments
if (attachments != null) {
for (String file : attachments) {
BodyPart append = new
MimeBodyPart();
FileDataSource fds = new
FileDataSource(file);
if (fds.getFile().canRead()) {

append.setDataHandler(new DataHandler(fds));

append.setFileName(fds.getFile().getName());

multipart.addBodyPart(append);
}
}
}
msg.setContent(multipart);
Transport.send(msg);


s pozdravem
Vladimír Náprstek
RWE Interní služby, s.r.o
Aplikační kompetenční centrum
Klíšská 940, 401 17 Ústí nad Labem
Tel. (vnitřní):(984) 5102
Tel. (vnější):+420 475 325 102
Mobile:   +420 739 535 915
E-mail:vladimir.naprs...@rwe.cz




Dusan Zatkovsky píše v Po 30. 11. 2009 v 13:00 +0100:

> Ahoj.
> 
> Zapasim so $SUBJ a zacinam byt znacne strateny.
> 
> Potrebujem poslat email pomocou java mail z windows, ktory ma v sebe cesky 
> text a attachment. Uz sa s tym lamem 2 hodiny a nemozem tomu prist na klb.
> 
> Kod:
> 
> MimeBodyPart text_part = new MimeBodyPart();
> text_part.setText(message_text);
> text_part.setHeader("Content-Type", "text/plain; charset=\"" + 
> System.getProperty("file.encoding") + "\"");
> text_part.setHeader("Content-Transfer-Encoding", "quoted-printable");
> 
> Nasledne to posielam ako multipart s attachmentom.
> Vysledkom je, ze thunderbird to zobrazi ok, cokolvek ine (outlook) zle.
> 
> Uryvok na disk ulozeneho multipart:
> 
> Return-Path: 
> Delivered-To: t...@test.cz
> Received: (qmail 5290 invoked by uid 89); 30 Nov 2009 11:49:43 -
> Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
> DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
>   s=private; d=test.cz;
>   b=YCY6ijt89eDlbCYX5hlSsXNTtBiPYnBECNPYxwcWN8Lv/+SvW7MAsx6YmGH0H406;
> Received: from unknown (HELO xpprim) (dusan.zatkov...@test.cz@93.185.97.186)
>   by server1.test.cz with ESMTPA; 30 Nov 2009 11:49:43 -
> Date: Mon, 30 Nov 2009 12:49:43 +0100 (CET)
> From: f...@test.cz
> To: t...@test.cz
> Message-ID: <28848200.5.1259581783779.javamail.ad...@xpprim>
> Subject: =?Cp1250?Q?Zpr=E1v=E1_z_datov=E9_schr=E1nky_do_vlastn=EDch_ru?=
>  =?Cp1250?Q?kou_od_test,_s.r.o.,78501_=8Aternberk,_CZ?=
> MIME-Version: 1.0
> Content-Type: multipart/mixed; boundary="=_Part_3_8979901.1259581783639"
> 
> --=_Part_3_8979901.1259581783639
> Content-Type: text/plain; charset="Cp1250"
> Content-Transfer-Encoding: quoted-printable
> 
> Dne 09.10.2009 11:56:05 V=E1m byla doru=E8ena nov=E1 datov=E1 zpr=E1va s ID=
>  101737.
> -- CUT --
> --=_Part_3_8979901.1259581783639
> Content-Type: application/octet-stream; name=message.zfo
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename=message.zfo
> 
> MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAaCAJIAEggPoPHE6
> TWVzc2FnZURvd25sb2FkUmVzcG9uc2UgeG1sbnM6cT0iaHR0cDovL2lzZHMuY3plY2hwb2ludC5j
> -- CUT --
> 
> 
> Subject je dobre ( cesky ), telo uz nie. Skusal som rozne kombinacie charset 
> a 
> transfer encoding, vzdy to bolo zle.
> 
> Bol by niekto taky dobry a pastol mi sem example s fungujucou cestinou? 
> Copy-pastol som asi 3 example z webu a ani jeden nezafungoval.
> 
> Diky.
> 
> 


Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Kamil Podlesak
Subject je neco _uplne_ jineho. Tam je nutne pouzit
  MimeUtility.encodeText( subject, "UTF-8", "Q" )

2009/11/30 Dusan Zatkovsky :
> Ahoj.
>
>> Asi takto:
>>
>> MimeBodyPart text_part = new MimeBodyPart();
>> text_part.setText(message_text, "UTF-8");
>> text_part.setHeader("Content-Transfer-Encoding", "quoted-printable");
>>
>
> No a presne takto mi to nefunguje. Teraz si nie som 100% isty, ci v tomto
> pripade je zle len subject, alebo aj body.
>
> --
> Dusan
>
>
> ... tykajte mi
>


Re: JavaMail - posielanie mailov v cestine

2009-11-30 Thread Dusan Zatkovsky
On Monday 30 of November 2009 15:12:11 Vladimir Naprstek wrote:

Diky vsetkym, uz som to fixol.


-- 
Dusan


... tykajte mi