javax.mail problem/question

M

morc

hi,
i have a class that takes parameters into construcor:

MailTransport(String fromAddress, String[] toAddress, String subject,
String messageBody, Object[] attachment, String[] contentType)


i did not write MailTransport. so i do not understand how to use the
Object[] attachment, i have just been typing null an ti seems to work.

however i would like to attach a .txt file

how to i make a text file into Object[]???

if unclear i will attempt to clear anything up as i know i might be
difficult to understand.

thanks for any input
-morc
 
O

Oliver Wong

morc said:
hi,
i have a class that takes parameters into construcor:

MailTransport(String fromAddress, String[] toAddress, String subject,
String messageBody, Object[] attachment, String[] contentType)


i did not write MailTransport. so i do not understand how to use the
Object[] attachment, i have just been typing null an ti seems to work.

however i would like to attach a .txt file

how to i make a text file into Object[]???

if unclear i will attempt to clear anything up as i know i might be
difficult to understand.

thanks for any input

Try reading the documentation for the class.

I know of org.apache.axis.transport.mail.MailTransport, but you're
probably not talking about that class, as it doesn't have a constructor like
the one you describe (it only has a zero argument constructor).

- Oliver
 
M

morc

no it is not a built in class. someone else created it. sorry for being
unclear.

anyhow i think i found a more simpler way to ask my question.

is it possible to cast a File into an Object[]??
if so please let me know how cuz i can't get the syntax right an im
pulling me hair.

thanks agian
-morc
 
O

opalpa

This made me think of how emails can have multiple attachments. The
method might allow multiple attachments, that's why it takes an array.
You still don't know what kind of instances the method accepts. Inside
there might be some casting going on.

Good luck,

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/
 
L

Lothar Kimmeringer

morc said:
is it possible to cast a File into an Object[]??

Object[] arr = new Object[]{new File(myfile)};

But I rather doubt that this will work for your MailTransport-class.
Reading the documentation is definetly the best practise here.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
M

morc

The Object[] is called attachments and this is what hte method does too
it.
Now ive been looking through the javax.mail documentation and i still
don't understand.

if ( attachments != null && contents != null ) {

if (attachments.length > 0 && contents.length > 0 &&
attachments.length == contents.length) {
for (int i = 0; i < contents.length; i ++) {
BodyPart bodyPart2 = new MimeBodyPart();
bodyPart2.setDataHandler(new DataHandler(attachments,
contents));
multipart.addBodyPart(bodyPart2);
}
}
}
message.setContent(multipart);
message.saveChanges();
Transport trans = session.getTransport(to[0]);
//System.err.println("trans:"+trans);

trans.addTransportListener(this);
trans.connect();
trans.sendMessage(message, to);.


if anyone knows how i can get a .txt file too attach please tell me ..
im gona get fired :(
thanks
-morc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top