Hi, I have one jsp file and this file includes some include files ...... How do i send this jsp file as body of email using java mail ................ I did this by hot coding the tags and content ... i have to read the content from jsp file and this file include some images ........... Here is my code ... Please can any one help me .... import java.io.*; import java.util.Properties; import java.util.Date; import javax.mail.*; import javax.activation.*; import javax.mail.internet.*; public class sendhtml { public static void sendMess(String[] argv) {
More>>
Hi,
I have one jsp file and this file includes some include files ......
How do i send this jsp file as body of email using java mail ................
I did this by hot coding the tags and content ... i have to read the content from jsp file and this file include some images ...........
Here is my code ... Please can any one help me ....
import java.io.*;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.activation.*;
import javax.mail.internet.*;
public class sendhtml {
public static void sendMess(String[] argv) {
String to, subject = "hello", from = null,
cc = null, bcc = null, url = null;
String mailhost = "xx.xxx.xx.xx";
String mailer = "sendhtml";
String protocol = null, host = null, user = null, password = null;
String record = null; // name of folder in which to record mail
boolean debug = false;
try {
to="xxx@yahoo.com";
Properties props = System.getProperties();
// could use Session.getTransport() and Transport.connect()
// assume we're using SMTP
if (mailhost != null)
props.put("mail.smtp.host", mailhost);
// Get a Session object
Session session = Session.getDefaultInstance(props, null);
if (debug)
session.setDebug(true);
// construct the message
Message msg = new MimeMessage(session);
if (from != null)
msg.setFrom(new InternetAddress(from));
else
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false));
msg.setSubject(subject);
MimeMultipart mp = new MimeMultipart();
mp.setSubType("related");
MimeBodyPart mbp1= new MimeBodyPart();
String html =
"
"+
"
"+>
"
see the following jpg : it is a car! !!!!!
"+
"
hello
"+
"
"+
"
"+
"
end of jpg
"+
"
"+>
"
"+
"Every couple days for the next four weeks, we will send you new"+
"can successfully sell your home.
|
"+
"
";
mbp1.setContent(html,"text/html");
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource("/usr/local/images/dualsign.gif");
mbp2.setFileName(fds.getName());
mbp2.setText("This is a beautiful car !");
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setHeader("Content-ID","23");
FileDataSource fds1 = new FileDataSource("/usr/local/images/logo.gif");
mbp2.setFileName(fds1.getName());
mbp2.setText("This is a beautiful car !");
mbp2.setDataHandler(new DataHandler(fds1));
mbp2.setHeader("Content-ID","123");
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
msg.setSentDate(new Date());
Transport.send(msg);
System.out.println(mp.getCount());
System.out.println("
Mail was sent successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
<<Less