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 "";
}
}