javax.mail problem/question

Discussion in 'Java' started by morc, Feb 3, 2006.

  1. morc

    morc Guest

    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
    morc, Feb 3, 2006
    #1
    1. Advertising

  2. morc

    Oliver Wong Guest

    "morc" <> wrote in message
    news:...
    > 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
    Oliver Wong, Feb 3, 2006
    #2
    1. Advertising

  3. morc

    morc Guest

    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
    morc, Feb 3, 2006
    #3
  4. 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

    http://www.geocities.com/opalpaweb/
    opalinski from opalpaweb, Feb 3, 2006
    #4
  5. morc wrote:

    > 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:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
    Lothar Kimmeringer, Feb 3, 2006
    #5
  6. opalinski from opalpaweb, Feb 3, 2006
    #6
  7. morc

    morc Guest

    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
    morc, Feb 3, 2006
    #7
  8. morc

    Roedy Green Guest

    On 3 Feb 2006 09:42:37 -0800, "morc" <> wrote,
    quoted or indirectly quoted someone who said :

    >
    >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.


    You have been trying vainly to make sense of the Javadoc right?

    There are two easier sources of information. The Sun Javamail tutorial
    with the listings and my own well-commented program, the bulk emailer
    ..See http://mindprod.com/products1.html#BULK

    see http://mindprod.com/jgloss/javamail.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Feb 3, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    741
    Esmond Pitt
    Mar 27, 2005
  2. lizard
    Replies:
    0
    Views:
    1,763
    lizard
    Jan 30, 2006
  3. Andrew Thompson

    javax.servlet and javax.servlet.http

    Andrew Thompson, Apr 24, 2007, in forum: Java
    Replies:
    1
    Views:
    654
    newbie_at_tomcat
    Apr 25, 2007
  4. Lew
    Replies:
    1
    Views:
    612
    newbie_at_tomcat
    Apr 25, 2007
  5. Laura Schmidt
    Replies:
    13
    Views:
    145
    Lars Enderin
    May 30, 2014
Loading...

Share This Page