Monday 27 November 2017

Javamail Content Transfer Koding Binære Alternativer


5 Content-Transfer-Encoding Header-feltet. Mange innholdstyper som kan transporteres via e-post, er representert i deres naturlige format som 8-biters karakter eller binære data. Slike data kan ikke overføres via noen transportprotokoller. Eksempelvis RFC 821 begrenser e-postmeldinger til 7-biters US-ASCII-data med 1000 tegnlinjer. Det er derfor nødvendig å definere en standardmekanisme for omkoding av slike data til et 7-biters kortlinjeprogram. Dette dokumentet angir at slike kodinger vil angis av et nytt overskriftsfelt Content-Transfer-Encoding Feltet Content-Transfer-Encoding brukes til å indikere hvilken transformasjon som er brukt for å representere kroppen på en akseptabel måte for transport. I motsetning til innholdstypene, en spredning av innholdsoverførings-kodingsverdier er uønsket og unødvendig. Det er imidlertid ikke mulig å etablere bare en enkelt Content-Transfer-Encoding-mekanisme. Det er en bytte mellom ønsket om kompakt og eff ekte koding av i stor grad binære data og ønsket om lesbar koding av data som hovedsakelig er, men ikke helt, 7-bits data Av denne grunn er minst to kodingsmekanismer nødvendige en lesbar koding og en tett koding. Innholds - Overførings-kodingsfelt er utformet for å spesifisere en inverterbar kartlegging mellom den opprinnelige representasjonen av en datatype og en representasjon som kan utveksles lett ved hjelp av 7-bits posttransportprotokoller, som de som er definert av RFC 821 SMTP Dette feltet er ikke definert av noen tidligere standard Feltens verdi er et enkelt token som angir typen koding, som oppregnet nedenfor Formelt Disse verdiene er ikke sosialfølsomme. Det vil si, Base64 og BASE64 og bAsE64 er alle tilsvarende. En kodingstype på 7BIT krever at kroppen allerede er inne en syv-bit post-ready representasjon Dette er standardverdien - det vil si Content-Transfer-Encoding 7BIT antas hvis feltet Innholdsoverskrift-koding ikke er tilstede. Verdiene 8bi t, 7bit og binær betyr alt at NO-koding har blitt utført. Imidlertid er de potensielt nyttige som indikasjoner på typen av data som finnes i objektet, og derfor av typen koding som kanskje må utføres for overføring i en gitt transportsystem 7bit betyr at dataene er alle representert som korte linjer med US-ASCII-data 8bit betyr at linjene er korte, men det kan være ikke-ASCII-tegn oktetter med høyordensbitsettet Binært betyr at ikke bare ikke - ASCII-tegn er tilstede, men også at linjene ikke nødvendigvis er kort nok til SMTP-transport. Forskellen mellom 8bit eller noe annet tenkelig bitbredde-token og binærtoken er at binær ikke krever overholdelse av noen grenser på linjelengde eller til SMTP-CRLF-semantikken, mens bitbredde-tokens krever slik overholdelse Hvis kroppen inneholder data i en hvilken som helst bithastighet annet enn 7-bit, må den aktuelle bitbredde Content-Transfer-Encoding token brukes f. eks. 8bit for unen kodet 8 bit bredt data Hvis kroppen inneholder binære data, må binær innholdsoverførings-kodingstoken brukes. Skillet mellom innholdsoverførings-kodingsverdiene for binær, 8bit osv. kan virke ubetydelig, fordi alle av dem virkelig betyr ingen - det har ikke vært koding av dataene for transport. En klar merking vil imidlertid ha stor verdi for gateways mellom fremtidige posttransportsystemer med ulik evne til å transportere data som ikke oppfyller restriksjonene for RFC 821-transport. Ved publisering av dette dokumentet finnes det ingen standardiserte Internett-transporter som det er legitimt å inkludere ukodede 8-biters eller binære data i postlegemer. Det er derfor ingen omstendigheter der 8bit eller binær innholdsoverføringskodning faktisk er lovlig på Internett I tilfelle at 8-bit eller binær posttransport blir en realitet i Internett-post, eller når dette dokumentet brukes sammen med andre 8-bits eller binære kapasitetstransport mekanisme skal 8-biters eller binære legemer merkes som sådan ved bruk av denne mekanismen. De fem verdiene som er definert for feltet Content-Transfer-Encoding, impliserer ingenting om innholdstypen, bortsett fra algoritmen som den ble kodet for, eller kravene til transportsystemet hvis unencoded. Implementors kan om nødvendig definere nye Content-Transfer-Encoding verdier, men må bruke en x-token, som er et navn prefixed av X - for å angi sin ikke-standardstatus, for eksempel Content-Transfer-Encoding x - Ny koding I motsetning til innholdstyper og undertyper er opprettelsen av nye Content-Transfer-Encoding-verdier imidlertid eksplisitt og sterkt motløs, da det antas å hindre interoperabilitet med liten potensiell fordel. Deres bruk er bare tillatt som følge av en avtale mellom samarbeidende brukeragenter. Hvis et overskriftsfelt for innholdsoverføring og koding vises som en del av en meldingsoverskrift, gjelder den for hele legemet til denne meldingen. Hvis et overskriftsfelt for innholdsoverføring og koding vises som en del av et legeme p art s headers, gjelder det bare for kroppen til den kroppsdelen. Hvis en enhet er av typen multipart eller melding, er Content-Transfer-Encoding ikke tillatt å ha noen annen verdi enn en bitbredde, f. eks. 7bit, 8bit, etc eller binær . Det skal bemerkes at e-post er karakterorientert, slik at mekanismene beskrevet her er mekanismer for koding av vilkårlig byte-strømmer, ikke bitstrømmer. Hvis en bitstrøm skal kodes via en av disse mekanismene, må den først konverteres til en 8-bit byte strøm ved hjelp av nettverksstandardbitordre bigendian, hvor de tidligere bitene i en strøm blir de høyere rekkefølgebitene i en byte. En bitstrøm som ikke slutter ved en 8-biters grense, må være polstret med nuller. Dette dokumentet gir en mekanisme for å merke til tillegg av slik utfylling i tilfelle av innholdet Type, som har en polstringsparameter. Kodemekanismer definert her uttrykkelig kode all data i ASCII. For eksempel, anta at et foretak har headerfelter som f. eks. Dette burde være tolket for å bety at kroppen er en base64 ASCII-koding av data som opprinnelig var i ISO-8859-1, og vil være i det tegnsettet igjen etter dekoding. De følgende seksjonene vil definere de to standardkodingsmekanismer. Definisjonen av nytt innholds - Overførings-kodinger er eksplisitt motet og bør bare oppstå når det er absolutt nødvendig. Alt innholdsoverføringskodingsnavnområde, med unntak av det som begynner med X-, er eksplisitt reservert til IANA for fremtidig bruk. Private avtaler om innholdsoverførings-kodinger er også eksplisitt motet. - Transfer-Encoding-verdier kan bare brukes på bestemte innholdstyper Spesielt er det uttrykkelig forbudt å bruke noen andre kodinger enn 7bit, 8bit eller binær med et hvilket som helst innholdstype som rekursivt inneholder andre innholdstypefelter, særlig multipart og melding Innholdstypene Alle kodinger som er ønsket for legemer av typen multipart eller melding, må gjøres på det innerste nivået ved å kode selve legemet ved behov for å bli kodet. NOTE PÅ ENKODERENDE RESTRIKSJONER. Selv om forbudet mot å bruke innholdsoverførings-kodinger på data av typen multipart eller melding kan virke altfor begrensende, er det nødvendig å forhindre nestede kodinger, hvor data sendes gjennom en kodingsalgoritme flere ganger, og må dekodes flere ganger for å bli korrekt sett. Nestede kodinger legger til betydelig kompleksitet for brukeragenter bortsett fra de åpenbare effektivitetsproblemer med slike flere kodinger, kan de skjule den grunnleggende strukturen til en melding. Spesielt kan de innebære at flere avkodingsoperasjoner er bare nødvendig for å finne ut hvilke typer objekter en melding inneholder. Banning nestede kodinger kan komplisere jobben til bestemte postgateways, men dette virker mindre av et problem enn effekten av nestede kodinger på brukeragenter. NOTER OM FORHOLDET MELLOM INNHOLDSTYPE OG INNHOLD - TRANSFER - ENKODING. Det kan virke som Content-Transfer-Encoding kan utledes av characen teristikk av innholdstypen som skal kodes, eller i det minste at bestemte innholdsoverførings-kodinger kan bli mandatt for bruk med bestemte innholdstyper. Det er flere grunner til at dette ikke er tilfellet. Først, gitt varierende typer transporter som brukes til post, kan noen kodinger være hensiktsmessige for enkelte innholdstype transportkombinasjoner og ikke for andre. For eksempel i en 8-bitstransport ville det ikke være nødvendig med koding for tekst i visse tegnsett, mens slike kodinger er tydelig kreves for 7-bits SMTP. For det andre kan enkelte innholdstyper kreve forskjellige typer overføringskoding under forskjellige forhold. For eksempel kan mange PostScript-legemer bestå av korte linjer med 7-bits data og krever derfor lite eller ingen koding. Andre PostScript-kropper spesielt de som bruker binær kodingsmekanisme for nivå 2 PostScript, kan bare være rimelig representert ved hjelp av en binær transportkoding. Endelig, siden innholdstype er ment å være en åpen sluttspenning økningsmekanisme, strenge spesifikasjoner for en tilknytning mellom innholdstypene og kodene, kombinerer effektivt spesifikasjonen til en applikasjonsprotokoll med en bestemt lavere nivåtransport Dette er ikke ønskelig siden utviklerne av en innholdstype ikke må være oppmerksomme på alle de transport i bruk og hva deres begrensninger er. NOTER PÅ OVERTRYKKELSESKODER. De sitert-skrivbare og base64 kodene er utformet slik at konvertering mellom dem er mulig. Det eneste problemet som oppstår i en slik konvertering er håndtering av linjeskift. Når du konverterer fra sitert - Utskriftsvennlig til base64 En linjeskift må konverteres til en CRLF-sekvens. Tilsvarende bør en CRLF-sekvens i base64-data konverteres til en citerbar utskriftslinjepause, men KUN når man konverterer tekstdata. NOTER PÅ KANONISK ENCODING MODEL. Det var litt forvirring, i tidligere utkast til dette notatet, om modellen for når e-postdata skulle konverteres til kanonisk form og kodet, og spesielt hvordan dette pr Ocess vil påvirke behandlingen av CRLF, da representasjonen av nye linjer varierer sterkt fra system til system. Av denne grunn er en kanonisk modell for koding presentert som Vedlegg H.5. 1 Sitat-Utskrivbar Content-Transfer-Encoding. Quoted-Printable koding er ment å representere data som i stor grad består av oktetter som tilsvarer utskrivbare tegn i ASCII-tegnsettet. Det koder for dataene på en slik måte at de resulterende oktettene sannsynligvis ikke vil bli endret ved posttransport. Hvis dataene som blir kodet, er mest ASCII-tekst , den kodede dataformen forblir i stor grad gjenkjennelig av mennesker. En kropp som er helt ASCII kan også være kodet i Quoted-Printable for å sikre integriteten til dataene hvis meldingen skal passere gjennom en tegn-oversetter - og eller linjeinnpaknings gateway. I denne kodingen skal oktetter representeres som bestemt av følgende regler. Regel 1 Generell 8-biters representasjon. En ny oktett, unntatt de som indikerer en linjeskift i henhold til Newlinekonvensjonen av den kanoniske form av dataene som er kodet, kan representeres av en etterfulgt av en tosifret heksadesimal representasjon av oktetsverdien Sifrene i det heksadesimale alfabetet til dette formål er 0123456789ABCDEF Store bokstaver må brukes ved sending heksadesimale data, men en robust implementering kan velge å gjenkjenne små bokstaver ved kvittering. Eksempelvis kan verdien 12 ASCII-formefôr representeres av 0C, og verdien 61 ASCII EQUAL SIGN kan representeres av 3D Unntatt når følgende regler tillater en alternativ koding, denne regelen er obligatorisk. Rulje 2 Bokstavelig fremstilling Oktetter med desimalverdier på 33 til 60 inklusive, og 62 til og med 126, kan være representert som ASCII-tegnene som tilsvarer disse oktene EXCLAMATION POINT LESS THAN, og GREATER THAN gjennom TILDE, henholdsvis. Rule 3 White Space. Octets med verdier på 9 og 32 kan representeres som ASCII TAB HT og SPACE tegn, respe ctively, men MÅ IKKE være så representert på slutten av en kodet linje. Eventuelle TAB HT - eller SPACE-tegn på en kodet linje MÅ følgelig følges på den linjen med et utskrivbart tegn. Spesielt en på enden av en kodet linje som indikerer en myk linjeskift se regel 5 kan følge ett eller flere TAB HT - eller SPACE-tegn. Det følger at en oktett med verdi 9 eller 32 som vises på slutten av en kodet linje, må være representert i henhold til regel 1 Denne regelen er nødvendig fordi noen MTAs Melding Transport Agenter, programmer som transporterer meldinger fra en bruker til en annen, eller utfører en del av slike overføringer, er kjent for å legge linjer med tekst med SPACE, og andre er kjent for å fjerne hvite mellomromstegn fra enden av en linje. Derfor, når de avkodes en sitert - Skrivbar kropp, hvilket som helst etterfølgende hvitt mellomrom på en linje, må slettes, da det nødvendigvis vil bli lagt til av mellomtransportmidler. Rulje 4 Linjebryter. En linjeskift i en tekstdel, uavhengig av hva dens representasjon er foll På grunn av den kanoniske representasjonen av dataene som er kodet, må de representeres av en RFC 822 linjeskift, som er en CRLF-sekvens, i den kvitterte-skrivbare kodingen Hvis isolerte CR'er og LF'er, eller LF CR - og CR LF-sekvenser får vises i binære data i henhold til kanonisk form, må de representeres ved hjelp av henholdsvis 0D, 0A, 0A 0D og 0D 0A notater. Merk at mange implementeringer kan velge å kode lokal representasjon av ulike innholdstyper direkte Spesielt kan dette gjelde for vanlig tekstmateriale på systemer som bruker newline-konvensjoner annet enn CRLF-avgrensere En slik implementering er tillatt, men genereringen av linjeskift må generaliseres for å ta hensyn til tilfellet der alternative representasjoner av newline-sekvenser benyttes. Rule 5 Soft Line Breaks. The Quoted - Utskriftsvennlig koding KREVER at kodede linjer ikke skal være mer enn 76 tegn. Hvis lengre linjer skal kodes med den kodede kvitteringen, må det brukes myke linjeskift. Et likestegn som det siste tegnet på en kodet linje indikerer en slik ikke-signifikant myk linjeskift i den kodede teksten. Dermed hvis den raske form for linjen er en enkelt ukodet linje som sier Dette kan representeres, i den kodede utskriften , da dette gir en mekanisme som lange linjer er kodet på, slik at de blir gjenopprettet av brukeragenten. 76 tegngrensen teller ikke den etterfølgende CRLF, men teller alle andre tegn, inkludert alle like tegn. Siden bindestrekkarakteren - er representert som seg selv i den kodede kodingen, må det tas hensyn når det innkapsles en kodet utskriftskodet kropp i en flerartsenhet for å sikre at innkapslingsgrensen ikke vises hvor som helst i den kodede kroppen. En god strategi er å velge en grense som inkluderer en tegnsekvens som som aldri kan vises i et sitat-utskrivbart legeme. Se definisjonen av flerartede meldinger senere i dette dokumentet. NOTT Den angitte utskriftsbare kodingen representerer someth Et kompromiss mellom lesbarhet og pålitelighet i transportorganer Kodene kodet med den kodede utskrivbare kodingen vil fungere pålitelig over de fleste postgateways, men fungerer kanskje ikke perfekt over noen få gateways, spesielt de som involverer oversettelse til EBCDIC. Teoretisk kan en EBCDIC-gateway dekode et sitert utskriftslegeme og omkodes det med base64, men slike gateways eksisterer ikke. Et høyere nivå av tillit tilbys av basen64 Content-Transfer-Encoding En måte å få rimelig pålitelig transport gjennom EBCDIC gateways er å også sitere ASCII-tegn i henhold til regel 1 Se vedlegg B for mer informasjon. Fordi citerte utskriftsdata vanligvis antas å være line-orientert, kan det forventes at pausene mellom linjene med siterte utskriftsdata kan endres i transport, i på samme måte som vanlig tekstmelding alltid har blitt endret i internettpost når de passerer mellom systemer med forskjellige newline-konvensjoner. for en korrupsjon av dataene, er det sannsynligvis mer fornuftig å bruke base64-kodingen i stedet for den kodede utskrivbare kodingen.5 2 Base64 Content-Transfer-Encoding. Base64 Content-Transfer-Encoding er designet for å representere vilkårlig sekvenser av oktetter i et skjema som ikke er menneskelig lesbart Koderings - og dekodningsalgoritmene er enkle, men de kodede dataene er konsekvent bare ca. 33 prosent større enn de ukodede dataene. Denne kodingen er basert på den som brukes i Privacy Enhanced Mail-applikasjoner, som definert i RFC 1113 The base64-koding er tilpasset fra RFC 1113, med en endringsbase64 eliminerer mekanismen for innebygd klar tekst. En 65-tegns delmengde av US-ASCII brukes, slik at 6 biter kan representeres per utskrivbart tegn. Den ekstra 65. tegn,, brukes til å betegne en spesiell behandlingsfunksjon. NOTE Denne delmengden har den viktige egenskapen at den er representert identisk i alle versjoner av ISO 646, inkludert US ASCII, og alle tegn i delmengden er også representert identisk i alle versjoner av EBCDIC Andre populære kodinger, for eksempel kodingen som brukes av UUENCODE-verktøyet og basis85-kodingen som er spesifisert som en del av Nivå 2 PostScript, deler ikke disse egenskapene og oppfyller dermed ikke overføringsbehovene en binær transportkoding for post må møtes. Kodingsprosessen representerer 24-biters grupper av inngangsbiter som utgangsstrenger av 4 kodede tegn. Fremover fra venstre til høyre blir en 24-bits inngangsgruppe dannet ved å sammenkoble 3 8-bits inngangsgrupper. Disse 24 bitene er da behandlet som 4 sammenkædede 6-biters grupper, som hver er oversatt til et enkeltsiffer i base64-alfabetet Når koding av en bitstrøm via base64-kodingen, må bitstrømmen antas å bli bestilt med den mest signifikante bit første At er den første bit i strømmen høyordensbit i den første byten, og den åttende bit vil være lavordensbit i den første byte, og så videre. Hver 6-biters gruppe brukes som en indeks inn i en matrise av 64 utskrivbare tegn Karakteren referert til av indeksen, er plassert i utgangsstrengen Disse tegnene, identifisert i tabell 1 nedenfor, er valgt for å være universelt representativ, og settet utelukker tegn med særlig betydning for SMTP f. eks. CR, LF og til innkapslingsgrensene som er definert i dette dokumentet e g. Table 1 Base64-alfabetet. Utgangsstrømkodede bytes må være representert i linjer med ikke mer enn 76 tegn hver. Alle linjeskift eller andre tegn som ikke finnes i Tabell 1, må ignoreres av dekodingsprogramvare I base64-data angir andre tegn enn de i tabell 1, linjeskift og annet hvitt mellomrom sannsynligvis en overføringsfeil, om hvilken en advarselsmelding eller til og med en meldingavvisning kan være hensiktsmessig under noen omstendigheter. Spesiell behandling utføres dersom færre enn 24 bits er tilgjengelige på slutten av dataene som er kodet. En fullkodende kvantum er alltid fullført på enden av en kropp. Når færre enn 24 inngangsbiter er e tilgjengelig i en inngangsgruppe, legges nullbiter til høyre for å danne et integrert antall 6-biters grupper Utgangstegnposisjoner som ikke er nødvendige for å representere faktiske inngangsdata, er satt til tegnet Siden alle base64-inngangene er et integrert antall oktetter, kan bare følgende tilfeller oppstå 1 det endelige kvantet av kodende inngang er et integrert flertall på 24 biter her, den endelige enheten av kodet utgang vil være et integrert flertall på 4 tegn uten polstring, 2 det endelige kvantet av kodende inngang er akkurat 8 bits her, vil den endelige enheten av kodet utgang være to tegn etterfulgt av to utfyllingsfigurer, eller 3 det endelige kvantet av kodingsinngang er nøyaktig 16 bits her, den endelige enheten av kodet utgang vil være tre tegn etterfulgt av en utfyllende karakter . Det må tas hensyn til å bruke de riktige oktene for linjeskift hvis base64-kodingen blir brukt direkte på tekstmateriale som ikke er konvertert til kanonisk form. Spesielt bør tekstlinjeavbrudd være konvertering TED i CRLF-sekvenser før base64-koding Det viktige å merke seg er at dette kan gjøres direkte av koderen i stedet for i et tidligere kanonicaliseringstrinn i noen implementeringer. NB! Det er ikke nødvendig å bekymre seg for å sitere synlige innkapslingsgrenser innenfor base64-kodet deler av flerartsenheter fordi ingen bindestrekkarakterer blir brukt i base64-kodingen. Det kan være litt tett å lese, men Innholdsoverførings-kodingsdelen av RFC 1341 har alle detaljer. Situasjonen er ganske dårlig fra verre til verre Her s min oppsummering. SMTP, per definisjon RFC 821, begrenser e-post til linjer med 1000 tegn på 7 biter hver. Det betyr at ingen av bytesene du sender nedrøret, kan ha den mest betydelige høyeste rekkefølgen biten satt til 1.Inneholdet som vi vil sende vil ofte ikke adlyde denne begrensningen iboende. Tenk på en bildefil eller en tekstfil som inneholder Unicode-tegn. Bytes av disse filene vil ofte ha sin 8ste bit satt til 1 SMTP, gjør det ikke slik, så du du må bruke overføringskoding for å beskrive hvordan du har jobbet rundt feilparametoden. Verdiene for innholdsoverførings-kodingsoverskriften beskriver regelen du har valgt for å løse dette problemet.7Bit Encoding.7bit betyr ganske enkelt at Min data består bare av USA - ASCII-tegn, som bare bruker de nedre 7 bitene for hvert tegn. Du garanterer i utgangspunktet at alle byteene i innholdet allerede overholder restriksjonene i SMTP, og det behøver derfor ingen spesiell behandling. Du kan bare lese det som det er. Vær oppmerksom på at når du velger 7bit, er du enig i at alle linjene i innholdet ditt er mindre enn 1000 tegn i lengden. Så lenge innholdet ditt overholder denne regelen, er 7bit den beste overføringskoden, siden det ikke trengs ekstra arbeid for deg bare les skrive bytes som de kommer av røret Det er også lett å eyeball 7bit innhold og fornemmelse av det Ideen her er at hvis du bare skriver i ren engelsk tekst vil du ha det bra Men det var ikke sant i 2005 og det er ikke sant today.8Bit Encoding.8bit betyr at dataene mine kan inneholde utvidede ASCII-tegn, de kan bruke det 8. høyeste bittet for å angi spesialtegn utenfor de vanlige US-ASCII 7-bit tegnene. Som med 7bit er det fortsatt en linjegrense på 1000 tegn. gjør egentlig ikke noen transformasjon av bytesene som de er skrevet til eller lest fra ledningen. Det betyr bare at du ikke garanterer at ingen av bytesene vil ha den høyeste biten satt til 1. Dette virker som et steg opp fra 7bit siden det gir deg mer frihet i innholdet ditt. RFC 1341 inneholder imidlertid denne godbit. Ved utgivelsen av dette dokumentet finnes det ingen standardiserte Internett-transporter som det er legitimt å inkludere ukodede 8-bits eller binære data i postorganer. ingen omstendigheter der 8bit eller binær Content-Transfer-Encoding faktisk er lovlig på Internett. RFC 1341 kom ut over 20 år siden Siden da har vi fått 8bit MIME Extensions i RFC 6152. Men selv da kan linjegrenser fortsatt appl y. Legg merke til at denne utvidelsen IKKE eliminerer muligheten for at en SMTP-server begrenser linjelengder servere er gratis å implementere denne utvidelsen, men likevel sette en linjelengdegrense ikke lavere enn 1000 oktetter. Binær Encoding. binary er den samme som 8bit bortsett fra at der s ingen linjelengde restriksjon Du kan fortsatt inkludere noen tegn du vil ha, og det er ingen ekstra koding I likhet med 8bit RFC 1341 står det at det egentlig ikke er en legitim kodende overføringskoding RFC 3030 utvidet dette med BINARYMIME. Quoted Printable. Before 8BITMIME-utvidelsen , det trengte å være en måte å sende innhold som ikke kunne være 7bit over SMTP HTML-filer som kan ha mer enn 1000 tegn linjer og filer med internasjonale tegn er gode eksempler på dette The quoted-printable encoding Definert i Section 5 1 of RFC 1341 er designet for å håndtere dette Det gjør to ting. Defines hvordan du unnslipper ikke-amerikanske ASCII-tegn slik at de kan bli representert i bare 7-biters tegn Kortversjonen de får displ ayed som et like tegn sammen med to 7-bit tegn. Defines at linjene ikke vil være større enn 76 tegn, og at linjeskiftene vil bli representert ved hjelp av spesialtegn som deretter unngås. Quoted Printable, på grunn av rømming og korte linjer, er mye vanskeligere å lese av et menneske enn 7bit eller 8bit, men det støtter et mye bredere spekter av mulig innhold. Base64 Encoding. Hvis dataene dine stort sett ikke er tekster ex en bildefil, har du ikke mange muligheter. 7bit er utenfor bordet 8bit og binær ble ikke støttet før MIME-utvidelsen RFCs sitert-printable ville fungere, men er veldig ineffektiv. Hver byte kommer til å bli representert av 3 characters. base64 er en god løsning for denne typen data. Det koder for 3 råbyte som 4 amerikanske - ASCII-tegn, som er relativt effektiv RFC 1341 begrenser linjelengden til base64-kodet data til 76 tegn for å passe inn i en SMTP-melding, men det er relativt enkelt å administrere når du bare splitter eller sammenkaller vilkårlige tegn ved faste lengder. Den store ulempen er at base64-kodet data er ganske mye helt lesbart av mennesker, selv om det bare er ren tekst under.5. Innholdsoverskriften for overføringskoding .5 Innholdsoverførings-kodingsoverskriftsfeltet. Mange innholdstyper som kunne transporteres via e-post, er representert i deres naturlige format som 8-biters karakter eller binære data. Slike data kan ikke overføres via noen transportprotokoller. For eksempel begrenser RFC 821 e-postmeldinger til 7-biters US - ASCII-data med linjer ikke lenger enn 1000 tegn Det er derfor nødvendig å definere en standardmekanisme for omkoding av slike data til et 7-biters kortlinjeprogram. Dette dokumentet angir at slike kodinger vil bli indikert av et nytt Content-Transfer - Kodingsfeltfelt Feltet Content-Transfer-Encoding brukes til å indikere typen transformasjon som har blitt brukt for å representere kroppen på en akseptabel måte for transport. I motsetning til innholdstypene, en spredning av innholds - Overførings-kodingsverdier er uønsket og unødvendig. Det er imidlertid ikke mulig å etablere bare en enkelt Content-Transfer-Encoding-mekanisme. Det er en avvei mellom ønsket om en kompakt og effektiv koding av stor-binære data og ønsket om lesbar koding av data som hovedsakelig er, men ikke helt, 7-bits data Av denne grunn er minst to kodingsmekanismer nødvendige en lesbar koding og en tett koding. Innholdsoverførings-kodingsfeltet er utformet for å angi en inverterbar kartlegging mellom den opprinnelige representasjonen av en type data og en representasjon som lett kan byttes ved hjelp av 7-bits posttransportprotokoller, som de som er definert av RFC 821 SMTP Dette feltet er ikke definert av noen tidligere standard. Feltets verdi er et enkelt token som angir typen av koding, som oppregnet under Formelt. Disse verdiene er ikke sosialfølsomme. Det vil si, Base64 og BASE64 og bAsE64 er alle tilsvarende. En kodingstype på 7BIT krever at boen dy er allerede i en syv-bit post-ready representasjon Dette er standardverdien - det vil si Content-Transfer-Encoding 7BIT antas hvis feltet Innholdsoverskrift-koding ikke er tilstede. Verdiene 8bit, 7bit og binært betyr alt at NO-koding har blitt utført. Imidlertid er de potensielt nyttige som indikasjoner på typen av data som finnes i objektet, og derfor av typen koding som kanskje må utføres for overføring i et gitt transportsystem spesielt. Forskjellen mellom 8bit eller noe annet tenkelig bitbredde-token og det binære token er at binær ikke krever overholdelse av noen grenser på linjelengde eller til SMTP-CRLF-semantikken, mens bitbredde-tokens krever en slik tilslutning Hvis kroppen inneholder data i en hvilken som helst bithastighet annet enn 7-bits, må den passende bitbredde Content-Transfer-Encoding token brukes f. eks. 8bit for ukodede 8-bits brede data Hvis kroppen inneholder binære data, må binær innholdsoverførings-kodingstoken benyttes. Implementatorer kan om nødvendig definere nye Content-Transfer-Encoding-verdier, men må bruke en x-token, som er et navn prefikset av X - for å indikere sin ikke-standardstatus, f. eks. Content-Transfer-Encoding x - Ny koding I motsetning til innholdstyper og undertyper er opprettelsen av nye Content-Transfer-Encoding-verdier imidlertid eksplisitt og sterkt motløs, da det antas å hindre interoperabilitet med liten potensiell fordel. Deres bruk er bare tillatt som følge av en avtale mellom samarbeidende brukeragenter. Hvis et overskriftsfelt for Content-Transfer-Encoding vises som en del av en meldingsoverskrift, gjelder den for hele kroppen til meldingen. Hvis et overskriftsfelt Content-Transfer-Encoding vises som en del av en kroppsdel ​​s overskrifter, gjelder det bare for kroppen til den kroppsdelen Hvis en enhet er av type flerart eller melding, er innholdsoverføringskoding ikke tillatt å ha noen annen verdi enn en bitbredde, f. eks. 7bit, 8bit, etc eller binær. bør noteres at e-post er karakter-eller iented, slik at mekanismene beskrevet her er mekanismer for koding av vilkårlige oktetstrømmer, ikke bitstrømmer. Hvis en bitstrøm skal kodes via en av disse mekanismene, må den først konverteres til en 8-bit byte strøm ved hjelp av nettverksstandardbit rekkefølge big endian, der de tidligere bitene i en strøm blir de høyere rekkefølgebitene i en byte. En bitstrøm som ikke slutter med en 8-biters grense, må polstes med nuller. Dette dokumentet gir en mekanisme for å merke til tillegg av slik polstring i tilfelle av programmet Content-Type, som har en padding parameter. Kodingsmekanismer definert her uttrykkelig kode all data i ASCII. For eksempel, anta at et foretak har headerfelter som. Dette må tolkes for å bety at kroppen er en base64 ASCII-koding av data som opprinnelig var i ISO-8859-1, og vil være i det tegnsettet igjen etter dekoding. Følgende seksjoner vil definere de to standardkodingsmekanismer. Definisjonen av ny innholdsoverføring-enco Dings er eksplisitt motløs og bør bare oppstå når det er absolutt nødvendig. Alt innholdsoverføringskodingsnavnområde, med unntak av det som begynner med X-, er eksplisitt reservert til IANA for fremtidig bruk. Private avtaler om innholdsoverførings-kodinger er også eksplisitt motet. - Kodingsverdier kan bare brukes på bestemte innholdstyper Spesielt er det uttrykkelig forbudt å bruke andre kodinger enn 7bit, 8bit eller binær med ethvert innholdstype som rekursivt inneholder andre innholdstypefelter, særlig flerartet og meldingen Content-Types All encodings that are desired for bodies of type multipart or message must be done at the innermost level, by encoding the actual body that needs to be encoded. Enforex Salamanca Bewertungen Ebay. So knnen wir jedes Fliesen-Fachgeschft unterbieten und Sie profitieren von unseren gnstigen Preisen Bei uns finden Sie ber 60 verschiedene Villeroy und Boch Fliesen, darunter auch die Modelle Fleisen Moonlight, Newpo rt oder Bernina Fliesen - hier werden Sie ganz sicher fndig Enforex Salamanca Bewertungen Ebay Trade Binary Options Beginners Uk Dermastir Luxury - Fiale Elastina eBay Tratamiento facial y recupera tu juventud - descuento 72 - 42 Oferplan, Oferplan La Gaceta de Salamanca Wir bieten unseren Kunden natrlich den Rund-um-Service und fhren deshalb nicht nur die Grundfliesen, sondern auch die dazugehrigen Dekorfliesen und das entsprechende Zubehr zu Villeroy und Boch Fliesen Additionally, the association will not only serve professionals, but it will offer services and programs to the Chaldean Community Ganz einfach Wir kaufen Villeroy und Boch Fliesen, Agrob Buchtal Fliesen, Novabell Fliesen und andere Markenprodukte in groen Mengen ein und geben Ihnen unseren Einkaufsvorteil direkt weiter. Hier finden Sie erstklassige Markenware wie Villeroy und Boch Fliesen zu gnstigen Konditionen Wir haben es uns zur Aufgabe gemacht, Ihnen Top-Markenfliesen zu Discountpreisen anzubieten Enforex Salamanca B ewertungen Ebay Binary Options Live Trading Roo EBay Kuferschutz Abgesichert ber den eBay-Kuferschutz Weitere Details wird in einem neuen Fenster oder Camel Active Bourse Salamanca Portefe Mr Green Shapewear frei Jackpot genie Sanduhr Bewertungen kostenlos Roulette Casino Spiele ohne Download ebay Spielautomaten zum Verkauf brigens Sollten Sie das gewnschte Produkt einmal nicht auf unserer Website finden, schicken Sie uns einfach eine Anfrage per E-Mail und wir werden uns umgehend darum bemhen, Ihnen Ihr Wunschprodukt zum gnstigsten Preis zu besorgen Dermastir Luxury - Fiale Elastina eBay Tratamiento facial y recupera tu juventud - descuento 72 - 42 Oferplan, Oferplan La Gaceta de Salamanca Auf unserer Bestsellerliste stehen Villeroy und Boch Fliesen immer wieder ganz oben, denn diese sind im Handel in der Regel sehr teuer und gerade deshalb bei uns besonders beliebt, weil wir die Villeroy und Boch Fliesen zu unschlagbar gnstigen Preisen anbieten. Binary Option Trade Copier Software Ind icator V1 0.Hungary Stock Exchange Cotton Rates. berzeugen Sie sich selbst Wenn Sie bereits ein Angebot von Ihrem Fachgeschft haben, z ber eine bestimmte Menge spezieller Wandfliesen, schicken Sie es uns per E-Mail oder Fax zu und wir werden uns bemhen, den genannten Preis zu unterbieten Enforex Salamanca Bewertungen Ebay Original karton tasche und oder mit noch am Artikel befestigten Kazakhstan Exchange Rates In Solomon Islands EBay Kuferschutz Abgesichert ber den eBay-Kuferschutz Weitere Details wird in einem neuen Fenster oder Camel Active Bourse Salamanca Portefe Wir bieten Ihnen eine riesige Auswahl an Markenfliesen in unserem Sortiment Abertura Dos Mercados Dos Forex Rates Hoje Portugal Dermastir Luxury - Fiale Elastina eBay Tratamiento facial y recupera tu juventud - descuento 72 - 42 Oferplan, Oferplan La Gaceta de Salamanca Werfen Sie unbedingt auch einen Blick in unsere TOP-Angebote, hier knnen Sie nochmal krftig sparen. We will be recognized as the preeminent association repre senting health care professionals whose primary objective is to serve and enhance the good and welfare of our community Wir haben es uns zur Aufgabe gemacht, Ihnen Top-Markenfliesen zu Discountpreisen anzubieten Enforex Salamanca Bewertungen Ebay History Of Stock Market In Panama Sie fragen sich vielleicht, wie so etwas mglich ist Enforex Salamanca Bewertungen Ebay Das gilt selbstverstndlich fr alle Produkte, auch fr hochpreisige Markenprodukte wie Villeroy und Boch Fliesen oder Feinsteinzeug poliert EBay Mitglied seit den 16 Juni 2005 und 100 positive Bewertungen infoat Wir bieten Ihnen eine riesige Auswahl an Markenfliesen in unserem Sortiment. The CAAHP was established to provide a professional forum to educate health care providers from the Chaldean Community and to give them the opportunity to interact and network on a regular basis Enforex Salamanca Bewertungen Ebay Die Nummern zeigen die jeweilige Position, an der ein Bild in den Suchergebnissen aufgefhrt Of Free Binary Options T rading Signal Zgern Sie nicht, sondern wenden Sie sich vertrauensvoll an Fliesen-Adeneuer, Ihrem gnstigen Fliesen-Onlinehandel fr Markenfliesen Free Stock Market Games For High School Students Klicken Sie auf eines der kleinen Bilder, um eine vergrerte Ansicht zu erhalten und die Originalquelle des Bildes angezeigt zu bekommen Elastina. JAVAMAIL API FAQ. Q What is the JavaMail API A The JavaMail API is a set of abstract APIs that model a mail system The API provides a platform independent and protocol independent framework to build Java technology based email client applications The JavaMail API provides facilities for reading and sending email Service providers implement particular protocols Several service providers are included with the JavaMail API package others are available separately The JavaMail API is implemented as a Java optional package that can be used on JDK 1 4 and later on any operating system The JavaMail API is also a required part of the Java Platform, Enterprise Edit ion Java EE. Q How do I get an implementation of the JavaMail API A Oracle provides a royalty-free reference implementation, in binary form, that developers may use and ship The reference implementation includes the core JavaMail packages and IMAP, POP3, and SMTP service providers The reference implementation may be downloaded here. Q Where is A is part of the JavaBeans Activation Framework JAF JAF is part of the JavaBeans Glasgow specification and is included in Java SE 6 The JavaMail API uses JAF for data content handling. Q What JDK does the JavaMail API need A The JavaMail API requires JDK JRE 1 4 or higher The JavaMail API is a Java optional package, it is not part of the core Java SE but is included in Java EE. Q Where can I find a version of JavaMail for my favorite operating system A JavaMail is completely written in Java and will run on any operating system that supports the required version of the JDK No special version is needed for different operating systems. Q Do the JavaMail APIs work in web browsers A JavaMail will work in any browser that supports the required JDK version The Java Plug-in may be required to provide such support. Q Can I use JavaMail to read mail from my web mail account such as Yahoo or Hotmail A It depends Many web-based email services provide access only using a browser with These services cannot be accessed using JavaMail If the service also provides POP3 or IMAP access, JavaMail can probably be used to access it Contact your web email service provider for details Another helpful tool is MrPostman, a proxy server that provides POP3 access to Hotmail and Yahoo Mail, available at. Q What is IMAP A IMAP stands for Internet Message Access Protocol It is a method of accessing electronic mail messages stored on a possibly shared mail server In other words, it permits a client email program to access remote message stores as if they were local IMAP is defined by RFC2060.Q What is SMTP A SMTP stands for Simple Mail Transfer Protocol It is used to transfer RFC822-style messages between different mail hosts as well as to submit new messages to a host for delivery SMTP is in very wide use it originated in 1982 and is defined by RFC821.Q What is MIME A MIME and RFC822 are the standards for describing email messages that are sent across the Internet The subpackage which is part of the JavaMail APIs provides a complete implementation of these two packages MIME is specified by the following RFCs RFC2045 RFC2046 RFC2047.Q What is POP3 A POP3 stands for Post Office Protocol version 3 POP3 is a very limited protocol for accessing a single mailbox It is much less capable than IMAP POP3 is very widely used and is defined by RFC1939.Q What about support for MAPI, NNTP, Lotus Notes, and other service providers A We have no current plans to implement any of these providers However, the architecture of the JavaMail APIs provides for being able to easily plug-in third-party service providers It is our hope that third-parties will embrace the JavaMail APIs by writing providers for other standard and proprietary protocols See our Third Party Products page for the latest list of such providers. Q How do I store mail messages on my local disk A A local store provider can be used to store mail messages on a local disk The JavaMail API download does not include such a provider but a provider that supports the Unix mbox format is available in the JavaMail source repository that you can build yourself See this page for details In addition, several local store providers are available from third parties for different local store formats such as MH and Mbox See our Third Party Products page for the latest list of such providers. Q Where do I find documentation on the protocol providers A The protocol providers for IMAP, POP3, and SMTP support many features that are not part of the JavaMail API specification The documentation for these protocol providers is included in the JavaMail javadocs The package level documentation for each prot ocol provider package describes the properties that are supported by the protocol proivder In addition, the protocol providers include some classes and methods that applications can use to take advantage of provider-specific features Note that use of these properties, classes, and methods renders a program non-portable it may only work with Oracle s implementation of the JavaMail API See the IMAP POP3 and SMTP package javadocs for details. Q Is the JavaMail API implementation completely free Can I ship it along with my product A Yes The JavaMail API implementation is completely free and open source and you can include it in your product This release includes IMAP, POP3, and SMTP providers as well Please do read the license and ensure that you understand it The JavaMail license is described here. Q Can I get the source code for the JavaMail API implementation A Starting with JavaMail 1 4 2, the source code for the JavaMail API Reference Implementation is available under the CDDL or GPL o pen source licenses in the JavaMail project at You ll need Mercurial to check out the source code. Q Is JavaMail Y2K compliant A Yes Oracle s JavaMail implementation is Option-3 Y2K compliant Please see the file in the JavaMail package for more information. Q The answer to my question isn t here, where else should I look A In addition to the JavaMail API spec and javadocs available from our main web page , don t forget to check the and files for additional important information. You can reach the JavaMail team directly at You can use this address to report bugs Bugs can also be reported using the Issue Tracker at the JavaMail project. The Oracle Technology Network maintains a JavaMail forum, see the JavaMail Forum. jGuru also maintains a JavaMail FAQ, which you ll find at although it hasn t been updated in several years. Installation and Configuration. Q How do I install the JavaMail API implementation A Unzip the distribution zip file and edit your CLASSPATH environment variable to include t he file that was included with the JavaMail API distribution You will also need an implementation of the JavaBeans Activation Framework see below unless you re using JDK 1 6 or newer which includes JAF See the file also included in the download package for additional details and examples, as well as the following FAQ entry. Q I get a ClassNotFoundException when I run my program A You haven t set CLASSPATH properly See Setting the class path Windows or Setting the class path Solaris Linux in the JDK documentation Note that if you re running your program using java - jar , the CLASSPATH environment variable setting is ignored In that case you ll need to add the - classpath argument to the java command, or add the Class-Path header to the manifest file of your jar file See the Java Tutorial and this Wikipedia article for more information. Q How do I set my CLASSPATH on Windows A Detailed instructions are available here. Q How do I add the JavaMail library to my NetBeans Java Project A Use the Library Manager to create a library and add a reference to that library to your project. Inside Netbeans, open the Library Manager Tools Libraries from the main menu bar. Select New Library. Enter a library name, e g JavaMail , and hit OK Do not check server library. Make sure the new library is selected under Libraries on the left. Select the Classpath tab on the right and choose Add Jar Folder. Using the file browser, select from your JavaMail installation e g and hit Add Jar Folder to accept. Select the Javadoc tab and choose Add ZIP Folder. Using the file browser, select the folder where the JavaMail javadoc index files are e g javamail-1 4 3 docs javadocs , and hit Add ZIP Folder to accept. If you downloaded the JavaMail source code you can set the source code reference on the Sources tab This can be helpful for debugging Using the file browser, select the source root for the JavaMail sources javamail-1 4 3 mail src main java for 1 4 3 and hit Add Jar Folder to accept. Note If you are using JDK 1 5 0 or earlier you will need to add the JavaBeans Activation Framework library as well You can create a separate library in a manner similar to the above, or just add and javadoc source references if desired to this library definition. Now add a reference to this library to your project. Open your project in NetBeans and make sure the Projects tab is visible. Right click your project in the project explorer and select Properties. In the Properties dialog, select Libraries in the tree on the left and make sure the Compile tab is selected. Click Add Library. Locate and select the library you created above and click Add Library It should be added to the list of compile-time libraries. Click OK and you re done. Q How do I add the JavaMail library to my Eclipse Java Project A Create a user library for JavaMail and add a reference to that library to your project. From the Eclipse main menu, open Window Preferences. Open the tree to Java Build Path User Libraries and select the User Libraries no de. Choose New from the panel on the right. In the new library dialog, enter a user library name, e g JavaMail , and hit OK Do not check system library. Make sure the new library is selected and choose Add Jars. Browse to where JavaMail is installed and select. Select Javadoc location None and hit Edit to add a reference to the javadoc location This can be found at docs javadocs under the same folder where you installed JavaMail. You can also set the source code reference here if you downloaded the JavaMail source code Use javamail-1 4 2 mail src main java as the source root for 1 4 2 or glassfish mail src java as the source root for 1 4 1.Choose OK to close the Preferences dialog JavaMail is now installed as a Library in Eclipse. Note If you are using JDK 1 5 0 or earlier you will need to add the JavaBeans Activation Framework library as well You can create a separate library in a manner similar to the above, or just add and javadoc source references if desired to this library definition. Now use the JavaMail library in your Eclipse Java Project Eclipse 3 4.Open your project in Eclipse and be in the Java Perspective. Right click your project in the project explorer and select Build Path Configure Build Path. In the Properties dialog that opens, ensure Java Build Path is selected in the tree on the left and select the Libraries tab on the right. Click Add Library. Select User Library , then click Next. Locate and select the JavaMail library added in the previous step, click Finish , and you re done. This article explains how to make the JavaMail source code available to your Eclipse project. Q Does JavaMail include all the necessary mail servers A No, the JavaMail API package does not include any mail servers To use the JavaMail API package, you ll need to have access to an IMAP or POP3 mail server for reading mail and or an SMTP mail server for sending mail These mail servers are usually provided by your Internet Service Provider or are a part of your organization s networking in frastructure If you don t have access to such a mail server, see below. Q Where can I get the necessary mail servers A The University of Washington IMAP server supports multiple platforms UNIX, Windows 32bit, etc Get the source code from There are several free, all Java mail servers available, including Apache James and Java Email Server Sendmail is a popular non-Java SMTP server SubEthaSMTP is a Java library for implementing SMTP server functionality their web page also references other mail servers Many other vendors provide mail servers supporting Internet standards There are also many free, public mail servers that support the required mail protocols such as Gmail, Yahoo Mail, Hotmail, etc. Q What host name, user name, or password should I use A We do not provide a mail server for you to use You must use your own mail server, or one provided by your Internet Service Provider or the company you work for Your network administrator can give you the information necessary to configure Jav aMail to work with your mail server. Q How do I configure JavaMail to work through my proxy server A JavaMail does not currently support accessing mail servers through a web proxy server One of the major reasons for using a proxy server is to allow requests from within a corporate network to pass through a corporate firewall The firewall will typically block most access to the Internet, but will allow requests from the proxy server to pass through In addition, a mail server inside the corporate network will perform a similar function for email, accepting messages via SMTP and forwarding them to their ultimate destination on the Internet, and accepting incoming messages and sending them to the appropriate internal mail server. If your proxy server supports the SOCKS V4 or V5 protocol RFC1928 and allows anonymous connections, and you re using JDK 1 5 or newer and JavaMail 1 4 5 or newer, you can configure a SOCKS proxy on a per-session, per-protocol basis by setting the property as describ ed in the javadocs for the package Similar properties exist for the imap and pop3 protocols. If you re using older versions of the JDK or JavaMail, you can tell the Java runtime to direct all TCP socket connections to the SOCKS server See the Networking Properties guide for the latest documentation of the socksProxyHost and socksProxyPort properties These are system-level properties, not JavaMail session properties They can be set from the command line when the application is invoked, for example java - DsocksProxyHost myproxy This facility can be used to direct the SMTP, IMAP, and POP3 communication from JavaMail to the SOCKS proxy server Note that setting these properties directs all TCP sockets to the SOCKS proxy, which may have negative impact on other aspects of your application. Without such a SOCKS server, if you want to use JavaMail to access mail servers outside the firewall indirectly, you might be able to use a program such as Corkscrew or connect to tunnel TCP connections thro ugh an proxy server JavaMail does not support direct access through an proxy web server. Q When connecting to my mail server over SSL I get an exception like unable to find valid certification path to requested target A Your server is probably using a test certificate or self-signed certificate instead of a certificate signed by a commercial Certificate Authority You ll need to install the server s certificate into your trust store The InstallCert program will help. Alternatively, you can set the mail protocol property to the host name of your mail server See the javadocs for the protocol provider packages for details. Other common causes of this problem are. There s a firewall or anti-virus program intercepting your request. There s something wrong in your JDK installation preventing it from finding the certificates for the trusted certificate authorities. You re running in an application server that has overridden the JDK s list of trusted certificate authorities. Q While trying to run my p rogram on Linux I get a very strange error message and the program fails What did I do wrong A The error message often looks something like this. The problem is due to a buggy version of the unzip command used to unzip the JavaMail download package on Linux The unzip command corrupts the file Get a newer version of the unzip command, or use the JDK s jar command to unzip the package. Q How do I use JavaMail in an application run under a SecurityManager what permissions must I grant to the application and to JavaMail A When using JavaMail in an environment with a SecurityManager, JavaMail will sometimes fail to read the configuration files in the file The JavaBeans Activation Framework may have the same problem reading configuration files from the file These default configuration files are stored as resource files in the META-INF directory in the jar file. There are a number of debugging techniques that can be used to determine if this is the problem Setting the Session property to true or calling will cause JavaMail to print debugging messages as it attempts to load each configuration file A message of the form DEBUG can t load default providers file indicates that this problem might exist Similarly, setting the System property to true e g by running the program using java will cause JAF to print debugging messages as it attempts to load each resource file Finally, the JDK can produce helpful debugging output by setting the system property to access failure e g by running the program using java The command java will display other security debugging options. In addition to the permissions necessary to read the configuration files, the application and JavaMail will also need permission to connect to the mail servers it uses If the application uses System properties to configure JavaMail e g by passing the Properties object returned from to the Session constructor, as many of the JavaMail demo programs do , it will also need permission to use the System Properties object A lternatively, the application can use its own Properties object and be sure to set the property or the and properties see the method. To allow an application to use JavaMail under a SecurityManager, the application, JavaMail, and JAF will need permissions such as the following be sure to replace the host and path names with appropriate values add these to the security policy file used by the application. If you don t want to give the application read write permission to System properties, but you still want to be able to use System properties to configure the application, you can give the application only read permission to System properties and use the following approach. Q How do I configure Tomcat to allow me to use JavaMail in my web application A To run a web application using JavaMail, you can add the JavaMail file and, if you re not using JDK 1 6 or newer, the JavaBeans Activation Framework file to the lib directory under the directory in which you installed Tomcat This will cause Tomcat to include these jar files in its classpath automatically For details, see JNDI Resources HOW-TO in the Tomcat documentation. Alternatively, you can package the file and files in the lib directory of your web application package war file. Q When using JavaMail in my servlet, it is unable to find any of the JavaMail classes I ve added to the server s CLASSPATH A It is often necessary to completely restart the web server when changing the CLASSPATH. Q I m sure I ve set my CLASSPATH correctly, but I m still getting complaints about classes that can t be found, such as classes A The most common cause of problems like this is having more than one copy of in your CLASSPATH or available to your application In addition to checking your CLASSPATH setting, also look for copies in the jre lib ext directory of your JDK installation If you re running in a web server or application server, it may be providing its own version of in one of its directories You should only have one version of avail able to your application. Q My servlet can find the JavaMail classes, but JavaMail complains that it can t find a service provider for smtp or imap or address type rfc822 A Usually this is because JavaMail can t access the configuration files in possibly because of a security permission problem see this item for more details Also, make sure that you haven t extracted the contents you should include the unmodified file in the server s CLASSPATH. Q How do I access Gmail with JavaMail A JavaMail is capable of sending and reading messages using Gmail All that s required is to properly configure JavaMail I ll illustrate the proper configuration using the demo programs that come with JavaMail - and You can use these programs for basic testing to ensure that your networking is working properly, that you can connect to the servers, that your username and password are correct, etc This is important when debugging problems to determine whether the bug is in your code or is elsewhere. Note that you ll need to configure your Gmail account to enable less secure apps or you ll need to use OAuth2 authentication which is somewhat more complex. Let s assume your Gmail username is and your password is passwd. To read mail from your Gmail Inbox, invoke msgshow as follows. By reading the source code, you can see how these command line arguments are used in the JavaMail API You should first try using msgshow as shown above, and once that s working move on to writing and configuring your own program to use Gmail The following code fragment shows a simple way to incorporate the needed configuration in your application. To connect to Gmail using the POP3 protocol instead of the IMAP protocol, simply change the host name to and change imap to pop3 in the property name and protocol name in the above instructions. To send a message through Gmail, invoke smtpsend as follows. The smtpsend program will prompt for a subject and message body text End the message body with D on UNIX or Z on Windows. Again, y ou can read the source code to see how the command line arguments are used in the JavaMail API The following code fragment shows a simple way to incorporate the needed configuration in your application. There is, of course, more than one way to use the JavaMail API to accomplish the same goal This should help you understand the essential configuration parameters necessary to use Gmail. Q Why do I get AuthenticationFailedException when accessing Gmail A Most likely you failed to enable less secure apps. Q Why don t I see all my messages when accessing Gmail with POP3 A Gmail has settings that control which of your messages are available via the POP3 protocol See the Gmail settings page to change the configuration of your Gmail account. Q Why doesn t search find all the messages I expect when accessing Gmail with IMAP A Gmail does not fully support all IMAP features For details see this Gmail Help page. Q How do I delete a message in Gmail A Gmail does not follow the normal IMAP conventions f or deleting messages Marking a message as deleted and then expunging the folder simply removes the current folder s label from the message The message will still appear in the Gmail All Mail folder To delete a message, copy the message to the Gmail Trash folder, which will immediately remove the message from the current folder To permanently remove a message, open the Gmail Trash folder, mark the message deleted true , and expunge the folder. Q How do I access Yahoo Mail with JavaMail A JavaMail is capable of sending and reading messages using Yahoo Mail All that s required is to properly configure JavaMail I ll illustrate the proper configuration using the demo programs that come with JavaMail - and. Let s assume your Yahoo Mail username is and your password is passwd. To read mail from your Yahoo Mail Inbox, invoke msgshow as follows. By reading the source code, you can see how these command line arguments are used in the JavaMail API You should first try using msgshow as shown above, a nd once that s working move on to writing and configuring your own program to use Yahoo Mail The code fragment shown above for connecting to Gmail will also work for connecting to Yahoo Mail by simply changing the host name. To send a message through Yahoo Mail, invoke smtpsend as follows. The smtpsend program will prompt for a subject and message body text End the message body with D on UNIX or Z on Windows. Again, you can read the source code to see how the command line arguments are used in the JavaMail API The code fragment shown above for connecting to Gmail will also work for connecting to Yahoo Mail by simply changing the host name There is, of course, more than one way to use the JavaMail API to accomplish the same goal This should help you understand the essential configuration parameters necessary to use Yahoo Mail. Q How do I access Hotmail Windows Live mail with JavaMail A JavaMail is capable of sending and reading messages using Hotmail All that s required is to properly confi gure JavaMail I ll illustrate the proper configuration using the demo programs that come with JavaMail - and. Let s assume your Hotmail username is and your password is passwd. To read mail from your Hotmail Inbox, invoke msgshow as follows. By reading the source code, you can see how these command line arguments are used in the JavaMail API You should first try using msgshow as shown above, and once that s working move on to writing and configuring your own program to use Hotmail The code fragment shown above for connecting to Gmail will also work for connecting to Hotmail by simply changing the host name. To send a message through Hotmail, invoke smtpsend as follows. Note that I split the command over three lines for display, but you should type it on one line. The smtpsend program uses the System properties when creating the JavaMail Session, so the properties set on the command line will be available to the JavaMail Session. The smtpsend program will prompt for a subject and message body text End the message body with D on UNIX or Z on Windows. Again, you can read the source code to see how the command line arguments are used in the JavaMail API The code fragment shown above for connecting to Gmail will also work for connecting to Hotmail by simply changing the host name and changing the connect call to 587, username, password There is, of course, more than one way to use the JavaMail API to accomplish the same goal This should help you understand the essential configuration parameters necessary to use Hotmail. For more details, search Windows Live Hotmail help for POP3.Q How do I access with JavaMail A JavaMail is capable of sending and reading mess ages using All that s required is to properly configure JavaMail I ll illustrate the proper configuration using the demo programs that come with JavaMail - and. Let s assume your username is and your password is passwd. To read mail from your Inbox, invoke msgshow as follows. By reading the source code, you can see how these command line arguments are used in the JavaMail API You should first try using msgshow as shown above, and once that s working move on to writing and configuring your own program to use The code fragment shown above for connecting to Gmail will also work for connecting to by simply changing the host name. To connect to using the POP3 protocol instead of the IMAP protocol, simply change the host name to and change the protocol name imaps to pop3s in the above instructions. To send a message through invoke smtpsend as follows. Note that I split the command over three lines for display, but you should type it on one line. The smtpsend program uses the System properties when creating the JavaMail Session, so the properties set on the command line will be available to the JavaMail Session. The smtpsend program will prompt for a subject and message body text End the message body with D on UNIX or Z on Windows. Again, you can read the source code to see how the command line arguments are used in the JavaMail API The following code fragment shows a simple way to incorporate the needed configuration in your application. There is, of course, more than one way to use the JavaMail API to accomplish the same goal This should help you understand the essential configuration parameters necessary to use For more details, see the Outlook Blog. Q Where can I learn the basics about Internet email that I ll need to know to program JavaMail effectively A See one of the books referenced on our web page for a good background on Intern et email, MIME, SMTP, IMAP, POP3, etc. Q Where can I find some example programs that show how to use JavaMail A There are many example programs available for download on the JavaMail project page including simple command line programs illustrating various aspects of the JavaMail API, a Swing-based GUI application, a simple servlet-based application, and a complete web application using JSP pages and a tag library. Q What are some of the most common mistakes people make when using JavaMail A Unfortunately, the internet is full of copy and paste programmers who don t understand the code they re using, which has resulted in a lot of unnecessarily complex and often incorrect examples The most common mistakes are. Use of Almost all code should use instead, as described below. Calling the send method on a Transport instance variable As described below send is a static method and ignores the Transport instance you use to call it. Setting various socketFactory properties Long, long ago JavaMail did n t have built in support for SSL connections, so it was necessary to set these properties to use SSL This hasn t been the case for years remove these properties and simplify your code The easiest way to enable SSL support in current versions of JavaMail is to set the property to true Replace smtp with imap or pop3 as appropriate. Using an Authenticator just to supply a username and password There s really nothing wrong with using an Authenticator, it s just unnecessarily complex A more straightforward approach is to call the connect method that takes a username and password when connecting to a Store When sending a message, use the static method that takes a username and password. Q How do I send a message with an attachment A A message with attachments is represented as a MIME multipart message where the first part is the main body of the message and the other parts are the attachments There are numerous examples showing how to construct such a message in the demo programs included in the JavaMail download package To attach a file use the attachFile method of MimeBodyPart. Q How do I tell if a message has attachments A In the simplest case, a message of MIME type multipart mixed with more than one body part is likely a message with attachments As described above, there are more complex cases to consider as well In particular, messages may have arbitrary nesting of multipart mixed and multipart alternative parts and may include multipart related parts for embedded HTML and multipart signed and or multipart encrypted parts for secure messages It s up to you to decide how many of these cases you want to handle in your application before deciding that a message has an attachment Most applications take a very simple approach to this and handle only a few of the most commonly seen cases. Note that while it s recommended that attachments have a Content-Disposition of ATTACHMENT , and will usually have a file name, these are not requirements Some messages with attachments wil l have only one or none of these Looking for attachments by looking for a body part with these set will fail in some cases. In the simplest case, here s how to tell if a message has attachments. Q How do I read a message with an attachment and save the attachment A As described above, a message with an attachment is represented in MIME as a multipart message In the simple case, the results of the Message object s getContent method will be a MimeMultipart object The first body part of the multipart object wil be the main text of the message The other body parts will be attachments The demo program shows how to traverse all the multipart objects in a message and extract the data of each of the body parts The getDisposition method will give you a hint as to whether the body part should be displayed inline or should be considered an attachment but note that not all mailers provide this information So to save the contents of a body part in a file, use the saveFile method of MimeBodyPart. To sa ve the data in a body part into a file for example , use the getInputStream method to access the attachment content and copy the data to a FileOutputStream Note that when copying the data you can not use the available method to determine how much data is in the attachment Instead, you must read the data until EOF The saveFile method of MimeBodyPart will do this for you However, you should not use the results of the getFileName method directly to name the file to be saved doing so could cause you to overwrite files unintentionally, including system files. Note that there are also more complicated cases to be handled as well For example, some mailers send the main body as both plain text and html This will typically appear as a multipart alternative content and a MimeMultipart object in place of a simple text body part Also, messages that are digitally signed or encrypted are even more complex Handling all these cases can be challenging Please refer to the various MIME specifications and other resources listed on our main page. Q How do I find the main message body in a message that has attachments A The following approach will handle the most common cases Handling improperly formatted messages, messages with unknown charsets, and signed or encrypted messages, can make this much more complex. You can call the getText method with a Message object which is a Part. Q How do I find the attachments in a message A There s a wide variety of possible MIME structures for email A general solution can be quite complex since it would need to take into account signed and encrypted messages, among other issues Different mailers will use different MIME structure, and of course some mailers will have bugs in how they use MIME You need to decide which cases you need to support. In general, multipart alternative is used to contain different versions of the main message body, and so can be skipped because it doesn t contain any attachments Typically, a message with attachments will have a to p level multipart mixed content with the first body part containing the main message body The first part may be a simple text part, a multipart alternative with text plain and text html parts, or a multipart related with a text html part and associated images. Attachments will usually, but not always, have a Content-Disposition of attachment Attachments will usually, but not always, have a file name. So, a good approach to start with is to only consider messages with a top level multipart mixed content and then consider the parts after the first part to be attachments whether they say so or not And as I said above, signed and encrypted messages will make this more complex. Q How do I get all the unread messages in a folder A Search for all messages with the SEEN flag not set. Q Should I use the isMimeType method, or should I use instanceof on the object returned by the getContent method, when deciding how to process a message part A It is almost always more efficient to use the isMimeType method The demo program shows how to use the isMimeType method when traversing the parts of a message. Q When reading a multipart message, why is the getContent method returning an IMAPInputStream or SharedByteArrayInputStream instead of a MimeMultipart object A This usually happens because the JavaBeans Activation Framework JAF can t find the mailcap configuration file included in the file JAF uses the thread s context class loader to look for the configuration file If the context class loader is not set properly, this can fail Most application servers should set the context class loader properly, but at least some versions of Tomcat do not One workaround is to put the file in Tomcat s lib directory instead of including it in the war file Another workaround is to add code such as the following to the beginning of your application. And of course you should always make sure the message you re dealing with is a multipart message before calling the getContent method, using something like if multipart as described above and in this example. Q When I attach a file it gets a MIME type of application octet-stream instead of the correct MIME type A The FileDataSource class uses the JavaBeans Activation Framework JAF class MimetypesFileTypeMap to determine the MIME type of a file based on the extension of the filename The default mapping knows about only a few extensions You can add support for more extensions either programmatically or by adding a configuration file to your application For example, to map the extension to the MIME type application msword create a file with the single line. See the javadocs for the MimetypesFileTypeMap class for details. Q How do I manually set the MIME type for an attached file, for example in the case where the filename doesn t have an obvious extension A Subclass the FileDataSource class and override the getContentType method Note that with this approach you can t use the attachFile method. Q How do I create a multipart message with a part of a ny MIME type I choose A The JavaMail API includes builtin support for the most common MIME types, but to create a message that includes data in a MIME type that JavaMail does not already understand, you ll need to supply that data to JavaMail in a byte stream format The ByteArrayDataSource class in the pacakge in JavaMail 1 4 and later, or included in source code in the demo directory of older versions of the JavaMail download package, can help This class will take a String byte array, or InputStream and create a DataSource object that you can use as follows. You can specify any MIME type that you want The MimeBodyPart object can then be added to a MimeMultipart object in the usual way. Note that if you create a ByteArrayDataSource with an InputStream it first copies all of the data in the stream into memory This is necessary because a DataSource needs to be able to supply multiple InputStream objects so that JavaMail can read the data once to determine what Content-Transfer-Encoding is appropriate, and then read the data again to include the data in the message. Q Can I read or send a Microsoft Office document using JavaMail A JavaMail can read a Microsoft Office document as an attachment and save that document in a file Likewise, JavaMail can attach a Microsoft Office document to a message and send it as an attachment Use the MimeBodyPart saveFile and attachFile methods To process the content of a Microsoft Office document you ll need a separate library such as Apache POI. Q How do I create or process calendar appointments A The iCal4j project provides an API that might be useful More information about how different products, such as Microsoft Outlook, support calendar appointments is available here This blog entry might also be helpful. Q When should I use and when should I use A Almost all code should use The method creates a new Session the first time it s called, using the Properties that are passed Subsequent calls will return that original Session and ignore any Properties you pass in If you want to create different Sessions with different properties, won t do that If some other code in the same JVM e g in the same app server has already created the default Session with their properties, you may end up using their Session and your properties will be ignored This often explains why your property settings seem to be ignored Always use to avoid this problem. Q What is disconnected support A A mail client supporting disconnected operation will allow the user to access messages in a remote message store e g IMAP , cache parts of some of those messages locally, and break the connection to the server While in this disconnected state, the mail client can access the messages that have been cached, possibly deleting them or saving them to other folders When the mail client next connects to the remote message store, the changes made locally will be synchronized with the remote store Similarly, disconnected support may allow the client to send messages whe n there is no connection to the server, with the messages being queued until a connection to the server is available See also RFC 1733 and RFC 4549.Q How do I support disconnected operation using the JavaMail APIs A The JavaMail API specification defines interfaces that can be used by a mail client to support disconnected operation Our IMAP provider implements these interfaces the UIDFolder interfaces. Q How do I send secure email using the JavaMail APIs A The JavaMail APIs currently have no support for sending or receiving secure email The architecture of the JavaMail APIs allows such support to be easily added later, by us or by third parties Information on the current Email security standards S MIME and PGP can be found at Please browse our Third Party Products page for solutions from other vendors The most popular third party solution is the Bouncy Castle library. Q The writeTo method generates message text with lines that are neither the canonical MIME representation of the data i e using CRLF to terminate lines , nor using the canonical line separator of my platform e g n on UNIX How do I get either of these representations if I need them A In either case you ll need to create an appropriate FilterOutputStream to hand to writeTo The FilterOutputStream will need to accept lines with any of the common line terminators and write out lines with only the desired line terminator The following are examples of such filters NewlineOutputStream converts to the local platform s line terminator and is useful when writing a message to a file CRLFOutputStream converts to the MIME canonical CRLF line terminator and is useful when the canonical MIME format is needed e g to compute a digital signature. Q Can I use the JavaMail APIs to implement a mail server A The JavaMail APIs were not intended to help you implement a mail server Nonetheless, some of the utility classes, such as the MIME message parsing classes, might be of use to you In general you ll find that the JavaMail API errs on the side of simple instead of robust That s appropriate for a mail client, but a mail server would likely make different tradeoffs. Q Can I use the JavaMail APIs to add new user accounts to my mail server, remove user accounts from my mail server, or change the passwords for user accounts on my mail server A The JavaMail API does not include any facilities for adding, removing, or changing user accounts There are no standards in this area every mail server handles this differently. Q Can I use the JavaMail APIs to access my address book on my mail server A The JavaMail API does not include any facilities for accessing an address book There are no standards in this area every mail server handles this differently If you can figure out how your server does it, you might be able to find a Java API to access it For example, if your server stores address books in LDAP, you could use the JNDI API to access it. Q Why doesn t the MimeMessage class implement Serializable so that I can seri alize a message to disk and read it back later A The JavaMail API was designed to layer on top of existing email systems, using existing message formats The ability to use Java serialization was neither essential nor useful for such implementations, and thus was not considered a goal of the JavaMail API. The hard part about serializing a Message is retaining the pointers to the Folder, Store, and Session If you only want to save the content of the message, and not the object itself, the writeTo method of a message gives you everything you need If you want to create an entire email system based on serialized messages, you should be able to subclass Message et al and implement Serializable in your subclass. If you want to serialize other objects of your own that reference MimeMessages, the writeObject method of your object can use the writeTo method of MimeMessage, and the readObject method of your object can use the MimeMessage constructor that takes an InputStream Your class will need to provide a Session when constructing the MimeMessage. Q How do I write a Service Provider A Please read the Service Provider documentation for details In general, if you want to write a Store provider, you subclass possibly and a few others For a Transport provider, you subclass possibly and a few others Then you add the entry describing your provider to the registry If you re interested in writing a service provider for a protocol or messaging system not currently supported by the JavaMail API implementation, please contact us at. Q I m having trouble logging into my Microsoft Exchange server, even though I m sure I m using the correct username and password, what could I be doing wrong A When logging in to Exchange you need to use a username that s more than your simple login name For example, if your email address is , your Windows NT login name is juser , your NT domain name is dom , and your Exchange mailbox name is Joe User , then you would need to use a username of when logging in using JavaMail. Note also that there s a bug in Exchange 2007 The Exchange server advertises that it supports AUTH PLAIN, even though this Exchange documentation claims that it s not supported This causes JavaMail to choose PLAIN authentication, which will always fail To work around this Exchange bug, set the session property to true Change imap to imaps if you re using the imaps protocol. Q How do I encode a binary file before sending it and how do I decode it when I receive it A You don t need to JavaMail will automatically determine an appropriate encoding to use for your message parts before sending the message, and will automatically decode message parts when reading them The getInputStream method will return the decoded data. Q If I don t need to encode and decode attachments myself, when should I use the MimeUtility methods A The MimeUtility methods are useful in cases that JavaMail doesn t handle automatically for you One such case that occurs frequently is encoding of filenames T he base MIME spec does not allow header parameter values such as the filename parameter to be encoded in the same way that e g the Subject header may be encoded This restricts parameter values, and thus filenames, to ASCII However, some mailers actually do encode non-ASCII filenames using the MIME text encoding Applications that wish to interoperate with such non-standard mailers can use the encodeText method to encode filenames before calling the MimeBodyPart setFileName method, and can use the decodeText method to decode returned filenames See also this entry below if you need to encode filenames. Q I have data that s already encoded in e g base64, how do I tell JavaMail to send this data without re-encoding it A Use the PreencodedMimeBodyPart class, new in JavaMail 1 4.Q Even though JavaMail does all the encoding and decoding for me, I need to manually control the encoding for some body parts A In the rare case that you need to control the encoding, there are several ways to override JavaMail s default behavior A simple approach is as follows After creating the entire message, call and then use something like Content-Transfer-Encoding , base64 to force base64 encoding for the given body part. Another approach is to subclass MimeBodyPart and override the updateHeaders method so that it first calls and then sets the Content-Transfer-Encoding header as above. Q Why doesn t JavaMail properly encode and decode filenames in non-ASCII character sets A The filename is stored as a parameter in MIME headers Encoded filenames of the form ISO-8859-15 B 5OTkLUluZm8ucGRm are not part of the MIME spec A filename of the form A B C is a perfectly valid filename, not an incorrectly encoded filename JavaMail does not encode and decode filenames by default because doing so would violate the MIME spec. The base MIME spec does not allow for encoding parameters RFC 2231 defines a new way to include encoded paramters, including filenames, in MIME headers It is not compatible with the de fac to way that many older applications illegally encode filenames Even though JavaMail supports RFC 2231, that alone does not allow JavaMail to interoperate with these older programs Most recent email programs support RFC 2231 and JavaMail enables support for it by default starting in JavaMail 1 5 To enable RFC 2231 support in older JavaMail releases for encoded parameters, set the System properties and to true. If you choose to violate the MIME spec, in order to interoperate with other programs that also violate the MIME spec, JavaMail gives you all the tools you need to do so Starting with JavaMail 1 4, setting the System properties and to true will cause JavaMail to encode and decode the filename parameter using the non-RFC 2231 MIME encoding. Applications using earlier versions of JavaMail can use the following workaround to encode a filename. The workaround for decoding a filename is equally simple. String filename. Again, this is primarily for applications using old versions of JavaMail Most applications should never need to use these methods. Q Why do I get an error such as Permission denied connect when connecting to my mail server using JDK7 A You may be running into this issue with support for IPv6 You can work around this problem by setting the System property to true You can do this when starting your program using java. Q How do I debug my application that uses JavaMail APIs A Turn on session debugging by invoking the method setDebug true on the Session object in your code That will cause debug information to be printed to the console, including a protocol trace If you passed the System properties to the Session when you created it, you can simply run your program with java If you think that you found a bug in JavaMail, send us this trace along with a test case that reproduces the problem, the platform you are using, the version of the JDK you are using, and the name and version of the mail servers IMAP, SMTP that you are using. Q How do I debug problems connectin g to my mail server A The first thing to do when debugging such problems is to determine whether it s a Java problem or a networking problem Use telnet to try to connect to the remote system For example, if you re having trouble connecting to the POP3 server named you would use. telnet 110.If you re trying to connect to an SMTP server, use 25 instead of 110 for the port number If you re trying to connect to an IMAP server use 143 for the port number. If you get a greeting banner you can simply disconnect If this works, your networking, name service, firewall, etc are all set up correctly and your problem is most likely in your Java program. If it doesn t work, you ll need to check your networking configuration or talk to your network administrator for help Sometimes a firewall installed on your local machine or on your network will prevent you from connecting to the server If telnet complains that it doesn t know the host name that you re using, most likely your name service e g DNS isn t properly configured to resolve internet host names None of these problems are JavaMail or Java problems. Usually, when you get a low level SocketException when connecting, the problem is due to your networking configuration Usually it s not a Java problem. If you ve succeeded in connecting with telnet, the next thing to do is to turn on Session debugging and get the protocol trace when JavaMail tries to connect to the remote machine, as described above This will often include more detailed error messages from the server that will indicate the real source of the problem. Q How do I debug problems connecting to my mail server using SSL A Debugging SSL problems, and in particular certificate problems, can be difficult The file includes some useful information JavaMail uses the JDK s JSSE API to provide SSL support You can find information about debugging JSSE problems in the JSSE Reference Guide. Q How do I debug problems with Java security permissions A You can set the System property to de bug problems with Java security permissions To get the possible values for setting that property, the following command will print a help message java MyClass. Q I tried running your demos against my IMAP server, but I get an error A First verify that you indeed have an email account on the IMAP server Check with your system administrator about it Turn debug mode on, by invoking the method setDebug true on the session object in your code This will cause the IMAP protocol trace to be dumped on your screen Send us this trace The trace will be very useful to us for identifying the problem If you can, please send us vendor information about your IMAP server. Q I can read messages from my IMAP server with other mail clients, but even though I can connect to the server using JavaMail, when I use JavaMail to read some messages it fails Doesn t that mean there s a bug in JavaMail A No, not usually Most other mail clients make very little use of the rich IMAP protocol They use the IMAP protocol a s little more than a variant of the POP3 protocol, typically downloading the entire message to the client and parsing it in the client This allows them to avoid all sorts of parsing and protocol bugs in many IMAP servers, but of course it comes at the cost of being less efficient because they don t take advantage of the IMAP protocol s ability to fetch only the parts of the message that are needed These server bugs often manifest themselves as the following exception on the client Unable to load BODYSTRUCTURE. The best approach when running into server bugs of this sort is to contact the vendor of the server and get them to fix their product Contact and we ll help you pinpoint the problem so that you can report it to the server vendor If you can t get a fix from the server vendor, the following technique will often allow you to work around these server bugs. In some cases, the server may be so badly broken that loading the envelope data is not possible, which can cause the above workarou nd to fail because internally it first fetches the message flags and message size from the server In that case, the following approach will usually work. Q The IMAP provider seems to lose data when I fetch messages with large attachments A This is due to bugs in the partial fetch implementation of your IMAP server To workaround this server bug, set the property to false Refer to from the JavaMail package for more information. Q Does the IMAP provider cache the retrieved data A The IMAP provider fetches the data for a message from the server only when necessary The can be used to optimize this The header and bodystructure information, once fetched, is always cached within the Message object However, the content of a bodypart is not cached So each time the content is requested by the client either using getContent or using getInputStream , a new FETCH request is issued to the server The reason for this is that the content of a message could be potentially large, and if we cache this conten t for a large number of messages, there is the possibility that the system may run out of memory soon since the garbage collector cannot free the referenced objects Clients should be aware of this and must hold on to the retrieved content themselves if needed. Q I want to move messages between folders Should I use appendMessages or copyMessages A Use copyMessages if the messages to be copied moved belong to the folder on which this method is being invoked This is because some implementations can optimize this operation if the source and destination folder belong to the same backend Store Otherwise, use appendMessages. Q Retrieving large message bodies seems inefficient at times A If you are using the IMAP provider, you could try increasing the property the current default is 16k This will cause data to be fetched from the server in larger chunks Note that you risk the possibility of the JVM running out of memory when you do this. Q I get OutOfMemory errors when loading this large binary a ttachement A Increase the maximum JVM heapsize at startup Use the - mx option if using the standard JVM from Oracle Don t keep references to the content of messages not being used In certain cases, you could try streaming the message content using getInputStream as raw bytes, use and then discard the used data chunks. Q Why do I get the UnsupportedDataTypeException when I invoke getContent on a bodypart A The getContent method returns a Java object that represents the bodypart content For this to work, a JAF DataContentHandler corresponding to the content s MIME type must be registered Otherwise, the UnsupportedDataTypeException will be thrown In this case, you can use the getInputStream method to retrieve the content as a stream of bytes See the JAF docs for details on how to create and register your own DataContentHandlers. Q Why do I get the UnsupportedEncodingException when I invoke getContent on a bodypart that contains text data A Textual bodyparts i e bodyparts whose type is text p lain , text html , or text xml return Unicode String objects when getContent is used Typically, such bodyparts internally hold their textual data in some non Unicode charset JavaMail through the corresponding DataContentHandler attempts to convert that data into a Unicode string The underlying JDK s charset converters are used to do this If the JDK does not support a particular charset, then the UnsupportedEncodingException is thrown In this case, you can use the getInputStream method to retrieve the content as a stream of bytes For example. There are some commonly used charsets that the JDK does not yet support You can find support for some of these additional charsets in the JCharset package at. You can also add an alias for an existing charset already supported by the JDK so that it will be known by an additional name You can create a charset provider for the bad charset name that simply redirects to an existing charset provider see the following code Create an appropriate CharsetProv ider subclass and include it along with the META-INF services file and the JDK will find it Obviously you could get significantly more clever and redirect all unknown charsets to us-ascii , for instance. Q How do I process all the messages in an IMAP folder and add a listener to wait for the arrival of new messages A Open the folder, process all the messages in the folder, and check whether new messages have arrived the message count has increased If so, loop If not, add the listener, then wait for new messages e g by calling the idle method. Part of the key to understanding how this works is understanding when the server is allowed to notify the client of new messages, and when JavaMail will see those notifications Between getting the number of messages and adding the listener, JavaMail won t see any notifications of new messages By the time you do an operation that will allow JavaMail to see the notification, the listener will be in place. The following code illustrates the general appr oach Many details have been omitted. Q How do I reply to a message A To reply to a message, use the reply method on the Message object This method will return a new object with the headers set appropriately for a reply You ll need to supply the content of the message yourself If you have the content of the original message as a String, you can use a simple method such as the following to create the prototypical reply text, which inserts in front of each line. Q How do I forward a message A The approach used to forward a message depends on how you want to present the forwarded message It s straightforward to create a new MimeMessage, address it appropriately, and attach an existing message as an attachment to the new message To attach the original message to the new message, use code such as. If instead you want to create the new message with the text of the original message included in the new message, to forward the message inline , you can use an approach such as the following. You ll have to write the formatAddressList method using the toUnicodeString method of InternetAddress You ll also want to include appropriate error checking and test for null values. Q How do I send HTML mail A There are a number of demo programs included with the distribution that show how to send HTML mail If you want to send a simple message that has HTML instead of plain text, see the program in the demo directory If you want to send an HTML file as an attachment, see the example that shows how to send any file as an attachment. Q How do I send mail with formatted text using different fonts and colors A The simplest approach is to send a message using HTML text See above. Q How do I send mail with both plain text as well as HTML text so that each mail reader can choose the format appropriate for it A You ll want to send a MIME multipart alternative message You construct such a message essentially the same way you construct a multipart mixed message, using a MimeMultipart object constr ucted using new MimeMultipart alternative You then insert the text plain body part as the first part in the multpart and insert the text html body part as the second part in the multipart You ll need to construct the plain and html parts yourself to have appropriate content See RFC2046 for details of the structure of such a message. Q How do I send HTML mail that includes images A The simplest approach is to send HTML text with image tags that reference images on a public web site In this approach the images aren t actually included in the message, and so won t be visible if the user is not connected to the Internet when they read the message Note also that some mailers will refuse to display images that are on remote sites. Alternatively, you can construct a MIME multipart related message See RFC2387 for details of the structure of such a message A simple example follows. Q What s the difference between the Transport methods send and sendMessage A The send method is a static method and c an be used without needing an instance of a Transport object It is intended for the common, simple case of sending a single message using the default transport Internally, the send method will first call the saveChanges method on the message It will then create an appropriate new Transport object, call the Transport s connect method, call the Transport s sendMessage method to actually send the message, call the Transport s close method, and finally abandon the new instance of the Transport object to be collected by the garbage collector Actually, it s rather more complicated than that, but that s the general idea. As you can see, the static send convenience method is built on the more general per-instance sendMessage method There are a number of reasons for an application to use the sendMessage method directly The most common reasons are to improve performance by sending more than one message during a single connection, or to manually manage the connection so as to provide authenticatio n information. Q When I try to send a message I get an error like SMTPSendFailedException 530, Address requires authentication A You need to authenticate to your SMTP server The package javadocs for the package describe several methods to do this The easiest is to replace the call with username, password. You ll have to supply the appropriate username and password needed by your mail server. Q How do I use SSL or TLS when connecting to my mail server A To use SMTP over SSL, set the property in the Session properties To use the STARTTLS command set the property in the Session properties For example. Q I need to authenticate to my SMTP server so I call user, password and then to send the message, but it s not working A You should call addrs to send the message As described above the send method is a static convenience method that acquires its own Transport object and creates its own connection to use for sending it does not use the connection associated with any Transport object through whic h it is invoked. Q I modified this message, but the headers do not reflect the changes A You should call saveChanges after you create a new message or modify an existing message This will cause the headers to be reset and reflect your changes Note that the method calls this implicitly So if all you are doing is sending the modified message, you can skip calling saveChanges yourself saveChanges is a potentially expensive operation especially for large or deeply nested messages , so call it only when needed. Q I set a particular value for the Message-ID header of my new message, but when I send this message that header is rewritten A A new value for the Message-ID field is set when the saveChanges method is called usually implicitly when a message is sent , overwriting any value you set yourself If you need to set your own Message-ID and have it retained, you will have to create your own MimeMessage subclass, override the updateMessageID method and use an instance of this subclass. Q Why do I get an UnsupportedDataTypeException when sending this new message that I created A You probably set some content for your message using the setContent Object o, String type method For this to work, there must be a JAF DataContentHandler registered for the given type If not, you will get the UnsupportedDataTypeException See the JAF documents for more information In most cases the simplest workaround is to use a ByteArrayDataSource as described above. Q How can I explicitly set the SMTP FROM attribute when sending a message A The property can be used to set the SMTP FROM attribute If this property if absent, the message s From attribute is used If multiple threads need to send mail simultaneously, and each needs to set the From attribute, each thread should use its own Session object with its own Properties object The property can then be set on each Properties object for each Session and thus each thread independently Alternatively, each thread can use the class The setEnvelopeFrom me thod on that class can be used to set this value With this approach, all threads can use the same Session. Q I want to repeatedly send messages, to a different set of recipients each time But invoking causes a new Transport session to be established each time This is suboptimal in this case, so how do I get around this A Create an instance of the appropriate Transport object, connect to it and invoke the sendMessage method repeatedly For example. Q I get MessagingException 501 HELO requires domain address when trying to send a message A The SMTP provider uses the results of in the SMTP HELO command If that call fails to return any data, no name is sent in the HELO command Check your JDK and name server configuration to ensure that that call returns the correct data You may also set the property to the name you want to use for the HELO command. Q I get Must issue a STARTTLS command first when trying to send a message A Your SMTP server wants you to switch from a plain text connection to a secure connection using the STARTTLS command You can enable use of this command by setting the Session property to true This will cause the SMTP protocol provider to issue the STARTTLS command after connecting to the server See the file for additional information Also, the javadocs for the package has more information on the properties that can be set. Note that your server is most likely also going to want you to authenticate, as described in this entry. Q If I send a message to a bad address, why don t I get a SendFailedException or TransportEvent indicating that the address is bad A There is no end-to-end address verification on the Internet Often a message will need to be forwarded to several mail servers before reaching one that can determine whether or not it can deliver the message If a failure occurs in one of these later steps, the message will typically be returned to the sender as undeliverable A successful send indicates only that the mail server has accepted the message and will try to deliver it. Q When a message can t be delivered, a failure message is returned How can I detect these bounced messages A While there is an Internet standard for reporting such errors the multipart report MIME type, see RFC1892 , it is not widely implemented yet RFC1211 discusses this problem in depth, including numerous examples. In Internet email, the existence of a particular mailbox or user name can only be determined by the ultimate server that would deliver the message The message may pass through several relay servers that are not able to detect the error before reaching the end server Typically, when the end server detects such an error, it will return a message indicating the reason for the failure to the sender of the original message There are many Internet standards covering such Delivery Status Notifications but a large number of servers don t support these new standards, instead using ad hoc techniques for returning such failure messages This makes it very diffic ult to correlate a bounced message with the original message that caused the problem Note that this problem is completely independent of JavaMail JavaMail now includes support for parsing Delivery Status Notifications see the file in the JavaMail package for details. There are a number of techniques and heuristics for dealing with this problem - none of them perfect One technique is Variable Envelope Return Paths, described at The use of VERP with JavaMail and Apache James is described here. Q When I construct an InternetAddress object, why don t I get an exception if the address is illegal A The InternetAddress class only checks the syntax of the address As discussed above the InternetAddress class is not able to determine whether the address actually exists as a legal address It is not even possible to verify the host name if the application is running behind a firewall or isn t currently connected to the Internet. Q When I try to send a message, why do I get 550 Unable to relay for my - address A This is not a JavaMail problem This is an error reply from your SMTP mail server It indicates that your mail server is not configured to allow you to send mail through it Typically, mail servers for an organization will be configured to allow mail from within the organization to be sent to other addresses within the organization, or to addresses external to the organization It will also typically allow mail coming from an address external to an organization to be sent to addresses within the orgnaization What it will typically not allow is mail coming from an address external to the organization to be sent relayed to another address also external to the organization The configuration of the mail server determines whether such relaying is allowed, and which addresses are considered internal vs external Often mail servers will require you to authenticate before they will relay messages. Q When I try to send a message to for example Yahoo, why do I get an error that says connecti on refused A The host you re trying to connect to is most likely not running a mail server If you re trying to connect to a web mail service such as Yahoo, you can t usually use the web host name e g since this host doesn t run the required mail server Instead, you ll need to learn the name of the host running the required mail server contact your web mail provider for this information You can find this information for Yahoo at Note that some web mail providers don t offer this service, instead allowing you to access your mail only through a browser. If you re not trying to connect to a web mail account, but instead are trying to connect to a host on your local network, then most likely the host you re trying to connect to is not running a mail server Sometimes this will occur if you forget to set for example the property, which will cause you to try to connect to localhost Most Windows machines do not run a mail server, although many UNIX Solaris, Linux, etc machines do Thus, attempts to connect to localhost on Windows machines will usually fail with a connection refused error. Q When sending mail, why does it fail with an exception that includes a message something like 553 To send mail, first check your mail with a valid POP account A In order to prevent their use to send spam, some mail servers will require you to have a valid POP3 account and require you to login to that account before they ll let you send mail through that mail server This is simple to handle in JavaMail When you know that you re dealing with such a mail server, make sure you connect to your POP3 Store on that mail server before sending mail. Q I want to delete messages on a POP3 server I set the DELETED flag on those messages Then I call the expunge method, but I get a MethodNotSupportedException How do I delete messages when I use the POP3 provider A The expunge method is not supported by the POP3 provider Instead, after marking the messages to be deleted by setting the DELETED flag on those me ssages, close the folder with the expunge flag set to true That is, invoke. Q How can I retrieve POP3 UIDLs in messages obtained from the POP3 provider A This is possible with the POP3 provider See the package documentation for details. Q How can I tell which messages are new with POP3 A The POP3 protocol doesn t provide support for any permanent flags so the RECENT flag is of no use The package documentation discusses several strategies for dealing with this problem. Q Why does hasNewMessages always return false when using POP3 A The POP3 protocol provides no way to determine whether a folder has new messages. Q I set up a MessageCountListener as demonstrated in the monitor program but I m never notified of new mail in my POP3 INBOX A The POP3 protocol does not allow the client to see new messages delivered to the INBOX while the INBOX is open The application must close the INBOX and reopen it in order to see any new messages You will never be notified of new mail using the MessageCountLi stener interface with POP3 See the package documentation for more information. Q Why does getReceivedDate return null when using POP3 A The POP3 protocol does not provide information about when a message was received It may be possible to guess at the received date by looking at some message headers such as the Received header, but this is not very reliable. Q When using POP3 I get complaints about the SocketFetcher class A Most likely you have more than one version of or in your CLASSPATH Check the setting of CLASSPATH and check the jre lib ext directory in the JDK. Q When using POP3 I get complaints about the contentStream field A The error usually looks like. As above you ve mixed versions of the POP3 provider and You probably have an older version of in your CLASSPATH before the newer version that includes the POP3 provider. Q How do I access or create folders other than INBOX on my POP3 server A You can t POP3 servers only support a single mailbox per user Most mail readers that use PO P3 also maintain a local message store into which they copy incoming messages from the POP3 INBOX and allow you to file messages in other folders See this item for more information about local store providers. Q Why does the getSize method return a negative number when using POP3 A Your POP3 server is broken The POP3 provider uses the TOP command to fetch the headers for the message and the LIST command to determine the size of the entire message It then subtracts the two values to determine the size of the message body If the server reports the size of the entire message incorrectly, you may get a negative number You can set the property to true to disable the use of the TOP command, but note that this will cause any access to the message headers to fetch the entire message. Q I m having problems using POP3 with Microsoft Exchange A Some versions of Microsoft Exchange do not implement the POP3 protocol properly They return different headers from the TOP command than they do from the RET R command This can cause all sorts of strange failures in JavaMail One solution is to disable use of the TOP command, as described above Another approach that works in some cases os to tell JavaMail to forget about the headers it retrieved using the TOP command after retrieving the entire message using the RETR command To do this, set the property to true. JavaMail in servlets. Q Can I use JavaMail in servlets A Yes, see the Installation and Configuration section above for more details The JavaMail API is also a required part of the Java Platform, Enterprise Edition Java EE No installation or configuration is necessary when using JavaMail in a Java EE product, it s just there. Q My web application uses JavaMail to attach and send a file that the user specifies, but my application can t find the file A If the user species the filename in an HTML form in the browser, the filename is normally the name of a file on the user s machine, not on the server The file will need to be uploaded to the server before JavaMail can access it The Apache Jakarta Commons FileUpload package can help. JavaMail in applets. Q Can I use JavaMail in applets A Yes, JavaMail will work in applets in browsers that support the required JDK version The Java Plug-in may be required to provide such support. Q What are the security implications of using JavaMail in an applet A One of the biggest issues with using JavaMail in applets is the default applet security restrictions These restrictions only allow applets to connect to the host from which they were loaded Thus, for such applets to use JavaMail, the mail server will need to be located on the same machine as the web server from which the applet is loaded You can find more information on the applet security model here. Q Ok, maybe I really don t want to use an applet, what should I do instead A In general, we recommend use of a web application to collect a mail message and send it using JavaMail The demo servlet included in the JavaMail download packag e illustrates this approach The Email Web Application demo program on the Oracle Technology Network illustrates another approach using JavaServer Pages.