473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

JavaMail API dropping attachments

Hello,

I'm building email messages and attachments via the JavaMail API,
which are then sent via sendmail. The attachments are mime attachments
of type "application/octet-stream". They are received via fine via
lotus notes and outlook, but in outlook express, yahoo, and hotmail
the attachment does not appear. Yahoo will even report the correct
message size. Any ideas on what the issue could be?

Any help would be greatly appreciated

John P.

below is the code:

package Frs.Tags;

import org.w3c.dom.*;
import Frs.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import oracle.sql.*;

public class tagSENDMAIL_ATTACHMENT implements TagHandler {
public String handleTag(Element el, FrsState state) throws
Exception {

// Get system properties
Properties props = new Properties();
Blob blob = null;
byte[] bytes = null;
String attachment_name = "";
// Setup mail server
props.put("mail.smtp.host", "blah.blah.com");

// Get session
Session sess = Session.getInstance(props, null);

if(sess == null){
props.clear();
props.put("mail.smtp.host", "blah2.blah.com");
sess = Session.getInstance(props, null);
}

// Define message
MimeMessage message = new MimeMessage(sess);

// ID
String id = FrsUtilAPI.getRequiredField(el, "ATTACHMENT_ID",
state);

if(!id.equals("") && id != null){
String query = "select name, img_blob from lds_image where id = "
+ id;
DbTool dbTool = null;
try
{
dbTool = DbTool.getDbConnection(query, DbTool.EXECUTE_QUERY);
ResultSet result = dbTool.getResultSet();
if (!result.next())
throw new Exception("Debug: cannot not fetch image from
db");
else{
attachment_name = result.getString(1);
blob = result.getBlob(2);
bytes = blob.getBytes(1, (int) blob.length());
}
}

catch (SQLException sqle)
{
if (dbTool != null)
{
dbTool.close();
dbTool = null;
}
}
catch (Exception e)
{
System.out.println("Debug: cannot get image id = " + id);
}

if (dbTool != null)
{
dbTool.close();
dbTool = null;
}
}
// Set the from address
String from = FrsUtilAPI.getRequiredField(el, "FROM", state);
System.out.println("FROM " + from);
if(!from.equals("") && from != null){
Address address = new InternetAddress(from);
message.setFrom(address);

// Set the to address
String to = FrsUtilAPI.getRequiredField(el, "TO", state);
System.out.println("TO " + to);
Address address2 = new InternetAddress(to);
message.setRecipient(Message.RecipientType.TO,addr ess2);

// Set the subject
String subject = FrsUtilAPI.getRequiredField(el, "SUBJECT",
state);
System.out.println("SUBJECT " + subject);
message.setSubject(subject);

// Get the switch value
String switch_value = FrsUtilAPI.getRequiredField(el,
"SWITCH", state);
System.out.println("SWITCH " + switch_value);

if(switch_value == null)
switch_value = "";

// Set the content
String body = FrsUtilAPI.getRequiredField(el, "BODY", state);

String body_alt = FrsUtilAPI.getRequiredField(el, "BODY_ALT",
state);

if(body_alt == null)
body_alt = "";

Multipart MP = new MimeMultipart("alternative");
BodyPart MBP = new MimeBodyPart();
BodyPart MBP_ALT = new MimeBodyPart();

if(switch_value.equals("on")){

MBP.setContent(body, "text/html");
MBP_ALT.setContent(body_alt, "text/plain");
MP.addBodyPart(MBP);
MP.addBodyPart(MBP_ALT);
}
else{
MBP.setContent(body, "text/plain");
MP.addBodyPart(MBP);
}

if(blob != null){
BodyPart MBA = new MimeBodyPart();
DataSource ds = new ByteArrayDataSource(bytes,
"application/octet-stream");
MBA.setDataHandler(new DataHandler(ds));
MBA.setFileName(attachment_name);
MP.addBodyPart(MBA);
}

message.setContent(MP);
// Send message
try{
Transport.send(message);
}

catch (SendFailedException SFE)
{
System.out.println("My generated exception: " + SFE);
}
}

return "";

}
}
Jul 17 '05 #1
0 5898

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonatan Fernstad | last post by:
I am using the JavaMail API to send email. It seems the Message.setSentDate(new Date()) sets wrong time zone. I am at GMT+1, and this is also what the new Date() is showing. But when the...
0
by: Rick Oosterholt | last post by:
I've accomplished to write attachments of messages to a file: message is attachment (original message . getContent()) 1) message.getInputStream() 2) write stream to file The problem is; -...
0
by: pcouas | last post by:
Hi, Anyone know how reading Outlook or Outlook express contact File from Javamail ? It seems theses files are named .dbx and .vba Thanks Philippe
1
by: Joshua | last post by:
Ive playedw ith the standard pop3 and imap and nntp and smtp modules but am unconvinced -- I would like to find a more sophisticated email handling API like JavaMail (from which I hope to convert)....
0
by: Eric E | last post by:
I have searched high and low for an example of implementing drag and drop of Outlook Attachments. I have a client that has the ability to record telephone conversations which end up as...
1
by: jimbo986 | last post by:
Outlook Email drag and drop -------------------------------------------------------------------------------- Problem: I need to allow my users to drag an email out of Outlook and drop it on a...
0
by: sandeepk84 | last post by:
Hi all... I am facing a problem in getting attachments from Yahoo Classic using JavaMail. My program reads the attachments from gmail and Yahoo Beta. But attachments of type pdf or txt from...
5
by: rengaraj | last post by:
Hello , I try a simple javamail program to send a mail.When i execute that javamail program, i got the error as follows import java.util.*; import javax.mail.*; import...
0
by: libia | last post by:
Hello, I want to send a mail using java program .so i used javamail 1.4 and jaf 1.1.It was compiled successfully.If i run the program it gives the error that "unable to connect" to port 25.If...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.