Really stuck with multipart message...

I post below the essence of my code... I read a lot of pages on the internet but my multipart message doesn't want to work :
With Outlook the mailer says that the encoding is unsupported and it attaches the multipart as a text file...
In outlook express the message is ok but the images used as datasources are attached a second time, as regular files. I have checked everything several times...
Thanks for any hint, I lost my day :-(
I use javamail API 1.3, jaf 1.0.2, jdk 1.3.1
I have an ArrayList for the datasources, one for their headers, another one for the urls to the fiels to attach and a last one for the file names. I have 3 datasources (gif images) and 2 attachments (xml and pdf). The multipart message code is snipped at the bottom.
Barbara
// creates mail session and mime message
this.mailSession = javax.mail.Session.getDefaultInstance(this.props, null);
this.msg = new MimeMessage(mailSession);
MimeBodyPart mbp1 = new MimeBodyPart();
Multipart mmp = new MimeMultipart();
//set from, to and cc fields ok
try{
this.msg.setSubject(this.subject,this.mimeCharSet);
this.msg.setSentDate(new java.util.Date());
catch(Exception e){}
// html ?
try{
if(html){
mbp1.setContent(this.body,"text/html");
mbp1.addHeaderLine("Content-Type: text/html;charset=" + this.mimeCharSet +"\"");
mbp1.addHeaderLine("Content-Transfer-Encoding: quoted-printable");
else{
mbp1.setContent(this.body, "text/plain");
mbp1.addHeaderLine("Content-Type: text/plain;charset=" + this.mimeCharSet +"\"");
mbp1.addHeaderLine("Content-Transfer-Encoding: 8bit");
mmp.addBodyPart(mbp1);
catch(Exception e){System.out.println("bug with content : " + e);}
// datasources and headers
try{
if(this.dataSources != null){
for(int j=0;j < this.dataSources.size();j++){
BodyPart mbp2 = new MimeBodyPart();
javax.activation.DataSource aSource = new URLDataSource(new URL((String) this.dataSources.get(j)));
mbp2.setDataHandler(new DataHandler(aSource));
mbp2.setHeader("Content-ID",(String) dsHeaders.get(j));
System.out.println("added datasource : " + this.dataSources.get(j));
mmp.addBodyPart(mbp2);
catch(Exception e){
System.out.println("bug with add datasources " + e);
// other attachments
try{
if(this.file != null){
for(int j=0;j < this.file.size();j++){
BodyPart mbp2 = new MimeBodyPart();
javax.activation.DataSource aSource = new URLDataSource(new URL((String) this.file.get(j)));
mbp2.setDataHandler(new DataHandler(aSource));
System.out.println("attached file : " + this.file.get(j));
try{
mbp2.setFileName((String) fileName.get(j));
catch(Exception e){// no filename
mmp.addBodyPart(mbp2);
this.msg.setContent(mmp);
catch(Exception e){
System.out.println("bug with add files " + e);
try{
javax.mail.Transport.send(this.msg);
catch(Exception e){
System.out.println("send mail failed : " + e);
Now the multipart message :
Received: from <snip> with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21)
     id P63WS3KF; Mon, 9 Sep 2002 16:57:07 +0200
Message-ID: <4650852.1031581670610.JavaMail.[snip]>
Date: Mon, 9 Sep 2002 16:27:49 +0200 (CEST)
From: =?iso-8859-1?Q?Barbara=A0Post?= <[snip]>
To: <snip>
Subject: Some subject
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_0_8194658.1031581669238"
------=_Part_0_8194658.1031581669238
Content-Type: text/html;charset=iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<snip of html code>
------=_Part_0_8194658.1031581669238
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: 69zzz@pc01
<snip of first included image code>
------=_Part_0_8194658.1031581669238
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: 69zzz@pc00
R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAQAICRAEAOw==
------=_Part_0_8194658.1031581669238
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: 69zzz@pc02
<snip of third included image code>
------=_Part_0_8194658.1031581669238
Content-Type: text/xml; name=nop41.xml; charset=Cp1252
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename=nop41.xml
<snip of xml attachement code>
------=_Part_0_8194658.1031581669238
Content-Type: application/pdf; name=nop41lt.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=nop41lt.pdf
<snip of pdf attachement code>
------=_Part_0_8194658.1031581669238--

Basic message structure required is
*{HEADERS}
*{MULTIPART MIME MESSAGE (RELATED)}
*>>>{PART 1 MULTIPART PART (ALTERNATIVE)}
*>>>>>>{PLAIN TEXT PART}
*>>>>>>{HTML TEXT PART}
*>>>{END PART 1 MULTIPART PART (ALTERNATIVE)}
*>>>{PART 2 INLINE IMAGE FILE (GIF/JPEG etc}
*>>>......
*>>>{PART n     }
*{END MULTIPART MIME MESSAGE (RELATED}
Snippet of code I use, but be aware all the html references to images etc are converted to cid:xxxxxxxxxxxx format outside of this code. No point in sending the image in the message if you refer to it by a url like http://www.foo.org/image1.gif
SH
<Code Snippet>
// create a message
msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setSubject(subject);
// create and fill the first message part with the Title and plain text
MimeBodyPart mbpa1 = new MimeBodyPart();
mbpa1.setText(ho.getTitle() + "\n" + ho.getText());
mbpa1.addHeaderLine("Content-Type: text/plain; charset=\"iso-8859-1\"");
mbpa1.addHeaderLine("Content-Transfer-Encoding: quoted-printable");
// Create and fill the second message part with the HTML code
MimeBodyPart mbpa2 = new MimeBodyPart();
mbpa2.setText(ho.getHTMLCode());
mbpa2.addHeaderLine("Content-Type: text/html; charset=\"iso-8859-1\"");
mbpa2.addHeaderLine("Content-Transfer-Encoding: quoted-printable");
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart("related");
Multipart mp2 = new MimeMultipart("alternative");
mp2.addBodyPart(mbpa1);
mp2.addBodyPart(mbpa2);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(mp2);
mp.addBodyPart(mbp1);
if (inline) {
// Enumerate the Image Names and add them to the message
for (Enumeration e = ho.getImageNames(); e.hasMoreElements();) {
String str = e.nextElement().toString();
MimeBodyPart mpi;
URL url2;
String fullStr = ho.getImageUrl(str);
if (inlineAll || ho.isImageLocal(fullStr)) {
if (debug)
System.out.println("Adding: " + fullStr);
url2 = new URL(fullStr);
mpi = new MimeBodyPart();
URLDataSource fds2 = new URLDataSource(url2);
mpi.setDataHandler(new DataHandler(fds2));
// mpi.addHeaderLine("Content-Location: " + fullStr);
if (ho.getCidValue(str).length() > 0)
mpi.setHeader("Content-ID", ho.getCidValue(str));
mp.addBodyPart(mpi);
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header note that the java.sql package also defines date
msg.setSentDate(new java.util.Date());
</Code Snippet>

Similar Messages

  • Stuck with a message on the touch screen - checking device

    This is an officejet 8500 wireless - the computer OS is Vista 64
    The touch screen on the printer is stuck with a message that says "checking device"  I cannot cancel or stop unless I unplug the printer. This occured after a paper jam.

    First, make sure there are no little pieces of paper left in the printer. This document can help you check it out:
    Paper Jams.
    If you still get the message on the screen, pull the power cord out while the printer is turned on. Wait 15 mseconds. Hold down the # and 6 keys on the front while you plug the power cord back in. This should reset the printer and, with luck, will clear the message.
    I am an employee of Hewlett Packard.
    - - Please mark Accept As Solution if it solves your problem so others can more easily find the answer - -
    - - Please click the Kudos star if you would like to say thanks - -

  • Im stuck with this message "no bootable device, insert boot disk and press any key". Now i want to go back to mac os but everytime i turn on my laptop that message appear..kindly help... Please

    Im stuck with this message "no bootable device, insert boot disk and press any key". Now i want to go back to mac os but everytime i turn on my laptop that message appear..kindly help... Please .... Im using my usb as bootable device but it cant be detected..

    Reboot, hold the option key down, select OSX when the startup manager appears.

  • TS3992 my ipad mini is stuck with the message on the screen 'this ipad hasn't been backed up in 5 weeks.  Backups happen when this ipad is plugged in, locked, and connected to Wi-Fi' with OK button.  If you click button nothing happens and I can't move an

    Ipad mini is stuck with the message 'this ipad hasn't been backed up in 5 weeks....' if you click the OK button nothing happens, cannot get rid of the message and cannot even power off b/c the message is on the screen.
    The ipad had not been backed up b/c it kept saying not enough storage available

    A reset may help. Tap and hold the Home button and the On/Off buttons for approximately 15-20 seconds, until the Apple logo reappears. When the logo appears, release both buttons.
    No content is affected by this procedure.

  • My 3GS on iOS5 seems to be really slow with text messages

    My 3GS on iOS5 seems to be really slow with text messages, any one else have this problem?

    Sometimes I think I don't get told about a message until I unlock my phone and when I do I get a notification and a text tone as I unlock and it can be off a conversation I was having 10/15 minutes ago.

  • I'm stuck with this message : en attente d'éléments à copier (étape 6 sur 6).

    Hi ! I'm from Québec, Canada, so maybe there's a lot of mistakes in the following.
    I've download IOS.5 this last sunday, and since everytime I sync my Ipod I'm stuck with this message in my Itunes:
    En attend d'éléments à copier (étape 6 sur 6)
    Can I unplug my Ipod even if it's not written : OK pour déconnecter.
    Help me please, or fix that bug with an update !
    Thanks a lot.

    Apple loops and jingles are free for you to use, here's the corresponding Apple document:
    http://support.apple.com/kb/HT2931

  • Whilst synching to my PC it said there was a software update for the iPhone. It is now stuck with a message saying connect to iTunes. I've tried resetting it in various ways but it still comes back to Connect to iTunes, but it won't. Help!

    Whilst synching to my PC it said there was a software update for the iPhone.
    It is now stuck with a message saying connect to iTunes. I've tried resetting it in various ways but it still comes back to Connect to iTunes, but it won't.
    Help!

    See Here  >  http://support.apple.com/kb/HT1808
    You may need to try this More than Once...
    But... if the Device has been Modified... this will Not necessarily work.

  • My ipad had a message saying it wasn't backed up and so I used my iPhone went to iCloud and instead of backing up I accidentally deleted ipad account now I am stuck with the message in my ipad and can't back it up

    My ipad had a message saying it wasn't backed up. So I went to iCloud on my phone but instead of backing up I accidentally deleted my ipad account from my iCloud now I am stuck with ipad with the message and can't back up. Can someone please tell me what can I do.

    On the iPad... Perform a Reset...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430

  • My book order gets stuck with the message 'your book order is not complete'

    hi,
    while trying to place my first order for a book, I get the message above, with the message that the book order is still being sent to the publisher.
    during the book submission, I went through what appeared to be a re-registration (although, using the same details, the right information seemed to be picked up in later stages of the process.)
    I am using Aperture 3 on Lion (10.7.1)
    oddly, I can't get into my 'order status' part of the Account part of the Apple store either.
    i'm not sure if something is incomplete, or what!
    anyone have any ideas, or has experienced this in the past?
    regards,
    Nick

    It seems that closing the application gives you the opportunity to cancel an 'in progress' book submission - the only way that I have come across. 
    Going in again and re-submitting has *thus far* done what is expected - I am now waiting for my confirmation email. 
    The address change screens are a bit of a mess, but that should not really make a huge difference if you are not having to change addresses - tabbing around the fields makes some sense of it. (apple, you may well want to fix this - contact me if screen shots would help)
    Nick

  • Phone is really slow with text messages

    hi, im new here and lookin for a little help. iv had the phone for a few months and now my curve freezes when i try to open a text message. also when i press send it freezes up. i dont have to restart it or anything but it takes about 7 seconds to regain itself. this only happens with text messages. emails work fine, facebook notifications work fine. i send and receive quite a bit of texts, emails, and facebook notifications and i have 14 applications. i did the update/ recovery& reboot thing on my computer. i have wifi preferred as my connection preference and tmobile is my mobile network. any tips? or do i have to just live with this?
    EDIT: i searched around on the forum a little bit and resolved the issue. i didnt know that it was only happening when i texted one person because i mostly only text this one person. but i guess i had to go to my phone book and text this person thru that instead of just replying. after that i can open and reply with no problem. sorry for takin up space on the forum. im new lol
    Message Edited by joeyrossmiller12 on 08-30-2009 11:56 PM

    Sometimes I think I don't get told about a message until I unlock my phone and when I do I get a notification and a text tone as I unlock and it can be off a conversation I was having 10/15 minutes ago.

  • HT204053 I have tried to download iCloud to my PC and am stuck with a message saying I must alter my Outlook Default profile. How ?

    I have tried to download icloud to my PC and amstuck with a message saying I must update my Outlook Default Profile. How ?

    You can not setup a new iCloud account using a PC. You must use an Apple device (Mac or iPhone/iPad) to create the account, then sign into it using your PC.

  • Really stuck with iPad mini since iOS7 download

    I downloaded iOS7 onto my iPad mini last night, when I woke up this morning the passcode no longer worked. I cannot get into the iPad to shek the IMEI number (something Apple don't seem to be able to talk to me without), I didn't set up the mini by syncing to a mac and cannot seem to restore either. This is really frustrating as it actually feels as though it's Apple's fault...can any one help me resolve this? I tried the emergency restore through itunes but stops halfway through to say it cannot complete restore to a passcode restricted device...I really am stuck

    Hi dataman.co.uk,
    Welcome to the Support Communities!
    The article below may be able to help you with this.
    Click on the link to see more details and screenshots. 
    iOS: Forgotten passcode or device disabled after entering wrong passcode
    http://support.apple.com/kb/HT1212?viewlocale=en_US
    If you have never synced your device with iTunes, or you do not have access to a computer
    If you see one of following alerts, you need to erase the device:
    "iTunes could not connect to the [device] because it is locked with a passcode. You must enter your passcode on the [device] before it can be used with iTunes."
    "You haven't chosen to have [device] trust this computer"
    If you have Find My iPhone enabled, you can use Remote Wipe to erase the contents of your device. If you have been using iCloud to back up, you may be able to restore the most recent backup to reset the passcode after the device has been erased.
    Alternatively, place the device in recovery mode and restore it to erase the device:
    Disconnect the USB cable from the device, but leave the other end of the cable connected to your computer's USB port.
    Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to shut down.
    While pressing and holding the Home button, reconnect the USB cable to the device. The device should turn on.
    Continue holding the Home button until you see the Connect to iTunes screen.
    iTunes will alert you that it has detected a device in recovery mode. Click OK, and then restore the device.
    Cheers,
    - Judy

  • I am really stuck with JCheckBox using it as a JTable cell editor...

    i need to focus next table cell, when user press a key on JcheckBox used in JTable as a cell editor.
    Especially i need to bind "ENTER" key with this action. I tried to addKeyListener do checkbox, tried to add action into input maps of jatble, and also to input map of checkbox. But really nothing works. Please help....
    Mathew, HSIGP

    and yes your code works well with any key, but when i want to assign something to "ENTER", it doesnt work. F.ex. if i assign something to "A" key
    like>
    InputMap m=table.getInputMap(WHEN_ANCETSTOR...);
    m.put(KeyStroke.get("A"),m.get(KeyStroke.get("TAB"));
    it works fine, and when i press "a" key it work as a "tab" key in table.
    But when i am doing same with "enter" instead of "a" it doesnt work.
    btw. there is action "actionselectNextCollumn..." assigned by default to enter
    why??

  • TS4576 My ipad is stuck with a message on the screen that won't go away.

    This message is stuck on my screen.  It won't let me click OK, and it prevents me from using the ipad.  What do I do?  I can't even turn it off. ""This iPhone hasn’t been backed up in 2 weeks...."

    Hold Sleep and Home buttons for 10 seconds until your iPad restarts

  • Really stuck with speeding up and slowing down clips

    Hi gang,
    I have been reading the Final Cut manual for the last hour and fooling around with my clips, but I can't get the effect that I want.
    I have a clip (CGI of a star field moving towards the observer) that I want initially to be frozen, then I want the clip to accelerate rapidly, and then end at about double normal speed. I thought I would be able to use keyframes and specify the playback rate at given points, but that option doesn't seem to exist. I have been playing with variable and constant speed settings, but these don't seem to work either.
    Ideally, the clip would go like this:
    1) first frame of original footage is frozen for 2 seconds.
    2) the original footage then begins playing, accelerating rapidly from frozen to double speed over 2 seconds.
    3) remainder of original footage plays at double speed until complete.
    I feel like I am missing something obvious, but I can't get it to work!
    Any suggestions appreciated.
    Cheers!

    Dude, I have the same problem. I found a picture/text tutorial on how to slow down, speed up and reverse all in one clip w/o chopping it up, but it was for FCP 4. I have 5 and when I ramp the green line down it speeds up, doesn't slow down. Is it just me or is the effect changed from FC4 to FC5.
    I'm looking for a great video tutorial for FC5 or similar on how to slow, speed up and reverse a clip using the Time Remap Tool in FC.
    If it's a DVD I have to buy so be it.
    Thanks everyone.

Maybe you are looking for

  • Gnome Login Manager??

    I have installed gnome extras and cant find the package with Login Manager. How do i changed themes and edit it so i dont have to enter password each time i log on? I have gnome-system-tools installed. Is there another package that contains the Login

  • Is Apple going to make TVs?

    Is Apple going to start making TVs?

  • How do you stop spell checking any "word" that has an underscore in it.

    I send lots of email that reference code.  Either with snipits, or mentioning variable names or file names etc. So I would I disable any spell check of any word that has an underscore character as part of it.  For example dont_check_this_var. I speci

  • Initial Offset Storage

    This is my first Labview app and I was denied the training course due to budget concerns, so this may be an elementary question.  I tried the online resources and could not make enough sense out of things to do what I need to do. I am acquiring four

  • Different Structure in 6.0 ?????

    I was very familiar with the old structure of /$WL_HOME/$PROJECT for single instances of WebLogic and /$WL_HOME/$PROJECT_CLUSTER/$SERVER for clusters, with each dir having a different weblogic.properties file. WebLogic Server 6.0 uses the terms domai