dcsimg
urgent help needed on java mail
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   candy_grill
Posted On:   Tuesday, December 17, 2002 02:22 PM

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

Re: urgent help needed on java mail

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, December 18, 2002 07:57 AM

For your original question, are you saying that you want to know how to execute a JSP, and capture its HTML response output page, as the body of an email message?



Or is the question about how to include the HTML page in the message, plus also include all its linked images too, as additional attachments, all bundled in one email message? (e.g. so the image tags reference attachments in the same message, rather than referencing URL's which have to be remotely retrieved, when the recipient views the HTML page)

Re: urgent help needed on java mail

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, December 17, 2002 02:41 PM

Question number one is, How are you verifying that all the destination addresses you have are really legitimate, and correct, and have someone reading them who has really requested that you send them email?

About | Sitemap | Contact