•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 370,604 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,034 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 13758 | Replies: 14
![]() |
hi experts,
Here there is a requirement in my project, like sending a automatic mail to a particular person,at particular time.
for examples:
If there is an expiry date for a customer's account, a week before the expiry date a mail should be send to the customer as a remainder.
But, at present I use to send mails manually.
If there is any suggestions or replies on this concept are appreciated.
Thanks,
Here there is a requirement in my project, like sending a automatic mail to a particular person,at particular time.
for examples:
If there is an expiry date for a customer's account, a week before the expiry date a mail should be send to the customer as a remainder.
But, at present I use to send mails manually.
If there is any suggestions or replies on this concept are appreciated.
Thanks,
techkar
•
•
Join Date: Apr 2006
Location: Mumbai, India
Posts: 351
Reputation:
Rep Power: 0
Solved Threads: 4
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,588
Reputation:
Rep Power: 18
Solved Threads: 188
not something you'd use JSP for anyway. A background process started from your crontab would be the most logical choice, or alternatively an autostarting servlet running a background thread if the functionality is an integral part of a web application.
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
•
•
Join Date: Jun 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
here is some example code , i use it to send google mail.
public void smtp(String receiver, String content) throws MessagingException {
if (smtpHost == null)
throw new MessagingException("smtpHost not found");
if (user == null)
throw new MessagingException("user not found");
if (password == null)
throw new MessagingException("password not found");
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost); //set smtp server
properties.put("mail.smtp.auth", "true"); //use smtp authen properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(properties,
new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
MimeMessage mimeMsg = new MimeMessage(session);
if (sender != null) {
mimeMsg.setFrom(new InternetAddress(sender));
}
if (receiver != null) {
mimeMsg.setRecipients(Message.RecipientType.TO, parse(receiver));
}
if (subject != null) {
mimeMsg.setSubject(subject, "GBK");
}
MimeBodyPart part = new MimeBodyPart();
part.setText(content == null ? "" : content, "GBK");
part.setContent(content.toString(), "text/html;charset=GBK");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(part);
mimeMsg.setContent(multipart);
mimeMsg.setSentDate(new Date());
Transport.send(mimeMsg);
}
public void smtp(String receiver, String content) throws MessagingException {
if (smtpHost == null)
throw new MessagingException("smtpHost not found");
if (user == null)
throw new MessagingException("user not found");
if (password == null)
throw new MessagingException("password not found");
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost); //set smtp server
properties.put("mail.smtp.auth", "true"); //use smtp authen properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(properties,
new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
MimeMessage mimeMsg = new MimeMessage(session);
if (sender != null) {
mimeMsg.setFrom(new InternetAddress(sender));
}
if (receiver != null) {
mimeMsg.setRecipients(Message.RecipientType.TO, parse(receiver));
}
if (subject != null) {
mimeMsg.setSubject(subject, "GBK");
}
MimeBodyPart part = new MimeBodyPart();
part.setText(content == null ? "" : content, "GBK");
part.setContent(content.toString(), "text/html;charset=GBK");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(part);
mimeMsg.setContent(multipart);
mimeMsg.setSentDate(new Date());
Transport.send(mimeMsg);
}
•
•
•
•
Originally Posted by lifayan
here is some example code , i use it to send google mail.
public void smtp(String receiver, String content) throws MessagingException {
if (smtpHost == null)
throw new MessagingException("smtpHost not found");
if (user == null)
throw new MessagingException("user not found");
if (password == null)
throw new MessagingException("password not found");
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost); //set smtp server
properties.put("mail.smtp.auth", "true"); //use smtp authen properties.put("mail.transport.protocol", "smtp");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(properties,
new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}
});
MimeMessage mimeMsg = new MimeMessage(session);
if (sender != null) {
mimeMsg.setFrom(new InternetAddress(sender));
}
if (receiver != null) {
mimeMsg.setRecipients(Message.RecipientType.TO, parse(receiver));
}
if (subject != null) {
mimeMsg.setSubject(subject, "GBK");
}
MimeBodyPart part = new MimeBodyPart();
part.setText(content == null ? "" : content, "GBK");
part.setContent(content.toString(), "text/html;charset=GBK");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(part);
mimeMsg.setContent(multipart);
mimeMsg.setSentDate(new Date());
Transport.send(mimeMsg);
}
for example: every, week end. (or) by date.
any idea, please suggest.
techkar
•
•
Join Date: Jun 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
that is simple ,if you use a j2ee container such as tomcat ,
here is a example
this is a ServletContextListener you should config it in web.xml so it will run auto when tomcat starts.
this is the web.xml config
<listener>
<listener-class>com.hecheng.util.ServletListenerTimmer</listener-class>
</listener>
you may need to change some field to fill your condition
public class ServletListenerTimmer implements ServletContextListener {
private java.util.Timer timer = null;
private Log mylogger = LogFactory.getLog(this.getClass());
public void contextInitialized(ServletContextEvent event) {
timer = new java.util.Timer(true);
mylogger.info("timmer is started");
timer.schedule(new SendReport(event.getServletContext()), 0, 60 * 60 * 1000);
mylogger.info("add sendmail task");
}
public void contextDestroyed(ServletContextEvent event) {
timer.cancel();
mylogger.info("timmer destoryed");
}
}
public class SendReport extends TimerTask {
private static final int C_SCHEDULE_HOUR = 22;
private static boolean isRunning = false;
private ServletContext context = null;
public SendReport(ServletContext context) {
this.context = context;
}
public void run() {
Calendar cal = Calendar.getInstance();
if (!isRunning) {
System.out.println("cal.get(Calendar.HOUR_OF_DAY) = " + cal.get(Calendar.HOUR_OF_DAY));
if (C_SCHEDULE_HOUR == cal.get(Calendar.HOUR_OF_DAY)) {
isRunning = true;
doReportTask();// you can write your sendmail task there
isRunning = false;
}
} else {
context.log("the prevenient task is still running!");
}
}
]
here is a example
this is a ServletContextListener you should config it in web.xml so it will run auto when tomcat starts.
this is the web.xml config
<listener>
<listener-class>com.hecheng.util.ServletListenerTimmer</listener-class>
</listener>
you may need to change some field to fill your condition
public class ServletListenerTimmer implements ServletContextListener {
private java.util.Timer timer = null;
private Log mylogger = LogFactory.getLog(this.getClass());
public void contextInitialized(ServletContextEvent event) {
timer = new java.util.Timer(true);
mylogger.info("timmer is started");
timer.schedule(new SendReport(event.getServletContext()), 0, 60 * 60 * 1000);
mylogger.info("add sendmail task");
}
public void contextDestroyed(ServletContextEvent event) {
timer.cancel();
mylogger.info("timmer destoryed");
}
}
public class SendReport extends TimerTask {
private static final int C_SCHEDULE_HOUR = 22;
private static boolean isRunning = false;
private ServletContext context = null;
public SendReport(ServletContext context) {
this.context = context;
}
public void run() {
Calendar cal = Calendar.getInstance();
if (!isRunning) {
System.out.println("cal.get(Calendar.HOUR_OF_DAY) = " + cal.get(Calendar.HOUR_OF_DAY));
if (C_SCHEDULE_HOUR == cal.get(Calendar.HOUR_OF_DAY)) {
isRunning = true;
doReportTask();// you can write your sendmail task there
isRunning = false;
}
} else {
context.log("the prevenient task is still running!");
}
}
]
•
•
•
•
Originally Posted by lifayan
that is simple ,if you use a j2ee container such as tomcat ,
here is a example
this is a ServletContextListener you should config it in web.xml so it will run auto when tomcat starts.
this is the web.xml config
<listener>
<listener-class>com.hecheng.util.ServletListenerTimmer</listener-class>
</listener>
you may need to change some field to fill your condition
public class ServletListenerTimmer implements ServletContextListener {
private java.util.Timer timer = null;
private Log mylogger = LogFactory.getLog(this.getClass());
public void contextInitialized(ServletContextEvent event) {
timer = new java.util.Timer(true);
mylogger.info("timmer is started");
timer.schedule(new SendReport(event.getServletContext()), 0, 60 * 60 * 1000);
mylogger.info("add sendmail task");
}
public void contextDestroyed(ServletContextEvent event) {
timer.cancel();
mylogger.info("timmer destoryed");
}
}
public class SendReport extends TimerTask {
private static final int C_SCHEDULE_HOUR = 22;
private static boolean isRunning = false;
private ServletContext context = null;
public SendReport(ServletContext context) {
this.context = context;
}
public void run() {
Calendar cal = Calendar.getInstance();
if (!isRunning) {
System.out.println("cal.get(Calendar.HOUR_OF_DAY) = " + cal.get(Calendar.HOUR_OF_DAY));
if (C_SCHEDULE_HOUR == cal.get(Calendar.HOUR_OF_DAY)) {
isRunning = true;
doReportTask();// you can write your sendmail task there
isRunning = false;
}
} else {
context.log("the prevenient task is still running!");
}
}
]
Regards.
techkar
•
•
Join Date: Aug 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
I want to send a mail in my jsp page , but i want that address of the mail to whom i have to send that address is to be send by another jsp page .i am attaching both my jsp
<%
Properties props = new Properties();
props.put("mail.smtp.host", "");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress(" ")
message.setFrom(from);
out.println("Kq");
InternetAddress to = new InternetAddress("to ");
out.println("K");
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("hi");
message.setText(" hello how r u");
Transport.send(message);
%>
In "to" i want address from other jsp , what should i try, i had use session
<%
Properties props = new Properties();
props.put("mail.smtp.host", "");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress(" ")
message.setFrom(from);
out.println("Kq");
InternetAddress to = new InternetAddress("to ");
out.println("K");
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject("hi");
message.setText(" hello how r u");
Transport.send(message);
%>
In "to" i want address from other jsp , what should i try, i had use session
Last edited by nitin saxena : Aug 23rd, 2006 at 11:51 pm. Reason: wrong code
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,588
Reputation:
Rep Power: 18
Solved Threads: 188
Kids, do your own homework.
Someone already posted a complete working solution (a really stupid thing to do as now people don't have to think anymore), and you still can't get it?
Someone already posted a complete working solution (a really stupid thing to do as now people don't have to think anymore), and you still can't get it?
42 Private messages asking for help will be ignored
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
In the frozen land of Nador they were forced to eat Steve's iMinstrels, and there was much rejoicing.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
- Previous Thread: org.apache.jasper.JasperException: Unable to load class for JSP
- Next Thread: Display Xml In Jsp



Linear Mode