WEB SERVICE AXIS TOMCAT 5.5.9 - SEND MAIL WITH FILE

Discussion in 'Java' started by Cyril, Jun 20, 2006.

  1. Cyril

    Cyril Guest

    Hello,

    I've a problem to send an email with text and file's attachment (pdf) in
    my WEB SERVICE. I'm send a email but it contains nothing except the
    subject And when i execute this class with a main the method send main
    run. Can you help to resolve this problem thank you very much

    SEE the member to send the file

    private boolean sendMsgAttachFile(String _to, String _subject, String
    _bodyText, String _fileName, int iddoc) {
    Properties props = new Properties();
    props.setProperty("mail.smtp.host", smtp);

    if (elogin != null && epass != null )
    {
    elogin.trim();
    epass.trim();
    //props.setProperty("mail.smtp.auth", "true");
    //Authenticator auth = new SMTPAuthenticator();
    //session = Session.getDefaultInstance(props, auth);
    session = Session.getDefaultInstance(props,null);
    } else {
    session = Session.getDefaultInstance(props,null);
    }
    try {
    File path_name = new File(RepCryptFile + _fileName);
    if (path_name.exists()) {
    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(emaildefault));
    InternetAddress[] address ={new InternetAddress(_to)};
    msg.setRecipients(Message.RecipientType.TO, address);
    msg.setSubject(_subject);
    MimeBodyPart textPart = new MimeBodyPart();
    //textPart.setHeader("Content-Transfert-Encoding", "8Bit");
    textPart.setText(_bodyText);
    MimeBodyPart attachFilePart = new MimeBodyPart();
    FileDataSource fds = new FileDataSource(RepCryptFile + _fileName);
    attachFilePart.setDataHandler(new DataHandler(fds));

    String name = selectnameoffile(Integer.toString(iddoc));
    attachFilePart.setFileName(name);
    Multipart mp = new MimeMultipart();
    mp.addBodyPart(textPart);
    mp.addBodyPart(attachFilePart);
    msg.setContent(mp);
    Transport.send(msg);
    logger.info("The email is sent with file: " + name
    + " mess: " + _bodyText + "file protect: " + RepCryptFile + _fileName);
    } else {
    logger.info("Error Send Mail: The email not send \n The file
    doesn't exit");
    return false;
    }

    } catch(MessagingException ex) {
    logger.fatal("Error Send Mail: ", ex);
    return false;
    } catch(Exception err) {
    logger.fatal("Error Send Mail: ", err);
    return false;
    }
    return true;
    }
    Cyril, Jun 20, 2006
    #1
    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:
    0
    Views:
    921
  2. hocho888
    Replies:
    1
    Views:
    624
  3. Digital Puer
    Replies:
    0
    Views:
    880
    Digital Puer
    Jun 21, 2005
  4. Michael Averstegge
    Replies:
    0
    Views:
    4,221
    Michael Averstegge
    Jan 10, 2006
  5. Digital Puer
    Replies:
    1
    Views:
    849
    Dag Sunde
    Jun 1, 2006
Loading...

Share This Page