Attach a file using
java api even it has to work in remote machine the following is the code i am using it is working in my local machine with file attachment please suggest what i have to do?
MimeMessage msg = new MimeMessage(session);
InternetAddress[] TheAddresses = InternetAddress.parse(sFrommailId);
msg.addFrom(TheAddresses);
TheAddresses = InternetAddress.parse(sTo);
msg.addRecipients(Message.RecipientType.TO,sTo);
msg.setSubject(sSubject);
MimeBodyPart mbp1 = new MimeBodyPart();
//mbp1.setText(sBody);
mbp1.setContent(sBody,"text/html");
MimeBodyPart mbp2 = new MimeBodyPart();
if (null != sCC)
{
TheAddresses = InternetAddress.parse(sCC);
msg.addRecipients(Message.RecipientType.CC,TheAddresses);
}
// attach the file to the message
System.out.println("Sending mail1234....");
FileDataSource fds = new FileDataSource(new File(sFileName));
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName()); // create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
// add the Multipart to the message
msg.setContent(mp);
Transport.send(msg);
Can any one give proper response for this it is so urgent!!! thanks in advance