dcsimg
Recieved mail shows attachment icon but no attachment
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jeppe_Skovbon
Posted On:   Monday, February 23, 2004 10:37 AM

I have made a mail program which should send an e-mail with an attachment txt file. When I run the program it sends an e-mail and is NOT catching any exceptions. When I recieve the mail at hotmail.com it shows an attachment icon but there isn´t an attachment file. My code is: public void send( Mail m ) throws SendFailedException, MessagingException { MimeBodyPart mbp1 = new MimeBodyPart(); MimeBodyPart mbp2 = new MimeBodyPart(); MimeMultipart multipart = new MimeMultipart("alternative"); Message msg = new MimeMessage(session); java.util.Vector v_To = m.getV_To(); for ( int iPos = 0; iPos < v_To.size(); iPos++ ){ m   More>>

I have made a mail program which should send an e-mail with an attachment txt file. When I run the program it sends an e-mail and is NOT catching any exceptions.



When I recieve the mail at hotmail.com it shows an attachment icon but there isn´t an attachment file.



My code is:

			
public void send( Mail m ) throws SendFailedException, MessagingException {

MimeBodyPart mbp1 = new MimeBodyPart();
MimeBodyPart mbp2 = new MimeBodyPart();
MimeMultipart multipart = new MimeMultipart("alternative");
Message msg = new MimeMessage(session);

java.util.Vector v_To = m.getV_To();
for ( int iPos = 0; iPos < v_To.size(); iPos++ ){

msg.addRecipient( javax.mail.Message.RecipientType.TO, new InternetAddress((String) v_To.get(iPos)));
}

msg.setFrom( new InternetAddress( m.getFrom() ) );
msg.setSentDate( new java.util.Date() );
//msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(m.getTo()));
try {

msg.setSubject(MimeUtility.encodeText(m.getSubj(), "iso-8859-1", "Q"));

} catch (UnsupportedEncodingException ue) {

msg.setSubject("Tilfredshedsundersøgelse"); //Hvis det sker, overskriver vi subject (skal være uden æøå!)
}

//mbp1.setDataHandler(new DataHandler(body, "text/html")); //til fremtid brug i forb. med HTML-mails
//mbp2.setDataHandler(new DataHandler(m.getBody(), "text/plain")); // forkert encoding
mbp2.setText(m.getBody(),"iso-8859-1");

multipart.addBodyPart(mbp2); //plain skal først, ellers fatter outlook det ikke
//multipart.addBodyPart(mbp1);
//file attachment
if ( m.getAttachmentFile() != null ){

mbp2 = new MimeBodyPart();
FileDataSource source = new FileDataSource( m.getAttachmentFile() );

if ( source != null ){

System.out.println("FILE EXIST "+m.getAttachmentFile());
}
else {

System.out.println("FILE NOT EXIST "+m.getAttachmentFile());
}

mbp2.setDataHandler( new DataHandler( source ) );
mbp2.setFileName( m.getAttachmentFileName() );
multipart.addBodyPart( mbp2 );
}
msg.setContent( multipart );
msg.saveChanges();
transport.sendMessage( msg, msg.getAllRecipients() );
} // send

Can anyone see what´s wrong???



Thanks    <<Less
About | Sitemap | Contact