WEB SERVICE AXIS TOMCAT 5.5.9 - SEND MAIL WITH FILE

C

Cyril

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

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,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top