This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Automated Mail Using Java,Apache Tomcat and Postgre,Quartz Scheduler? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Automated Mail Using Java,Apache Tomcat and Postgre,Quartz Scheduler?" Watch "Automated Mail Using Java,Apache Tomcat and Postgre,Quartz Scheduler?" New topic
Author

Automated Mail Using Java,Apache Tomcat and Postgre,Quartz Scheduler?

madhankumar kumaravelu
Greenhorn

Joined: Nov 30, 2011
Posts: 17

Hello

Struts,Postgre,Apache Tomcat Server,Hibernate

A mail has to be sent to the patient to complete the survey.
Please see the structure below:

From: ‘newhospital’ feedback@newhospital.com
Subject: Feedback regarding {Clinic Name}


Dear {Patient First Name};
{Clinic Name} is partnering with {Hospital Name} for a pilot program that aims to improve customer satisfaction. We hope you’ll take the opportunity to answer a few questions related to your recent visit.
To participate in the survey, please click this link:
http://{Clinic Name}.{Hospital Name}.com/survey/{visit_id}
Sincerely,
Admin
We wouldn’t ask if we didn’t care™
PS> We will send automatic reminder e-mails if we don’t hear from you. To opt out of the survey, please click this link, instead: http://{Clinic Name}.{Hospital Name}.com/survey/{visit_id}/decline.



If the patient clicks the accept link then it has to open the survey form.

The e-mail invitation will be template-driven, with a few variable substitutions, shown in curly brackets ({}). Each pilot customer may want a slightly different template. The e-mail will be a multipart format with a professional HTML partwith images, fonts, and color that degrades smoothly to a simple text part.

Please let me know which technolgies to use and how?

Thanks
Madhan









Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
You could use all of the frameworks you mention, or none. Are you familiar with Struts and Hibernate yet? If not, that's what I would start with.
madhankumar kumaravelu
Greenhorn

Joined: Nov 30, 2011
Posts: 17

Yes iam just aware and this is an real time project with strict deadline..

Please let me know how to do this with some sample code?

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I don't see any particular difficulty. What have you got so far, and where are you stuck making progress?
madhankumar kumaravelu
Greenhorn

Joined: Nov 30, 2011
Posts: 17


/**
*
*/

/**
* @author madhan
*
*/
/*
* Copyright (c) Ian F. Darwin, http://www.darwinsys.com/, 1996-2002.
* All rights reserved. Software written by Ian F. Darwin and others.
* $Id: LICENSE,v 1.8 2004/02/09 03:33:38 ian Exp $
*/

import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

import java.util.Properties;

/** SendMime -- send a multi-part MIME email message.
* @author Ian F. Darwin
* @version $Id: SendMime.java,v 1.8 2003/05/31 21:18:35 ian Exp $
*/
public class SendMime {

/** The message recipient. */
protected String message_recip = "madhan1979@gmail.com";
/* What's it all about, Alfie? */
protected String message_subject = "Re: your mail";
/** The message CC recipient. */
protected String message_cc = "madhan1979@gmail.com";
/** The text/plain message body */
protected String message_body =
"I am unable to attend to your message, as I am busy sunning " +
"myself on the beach in Maui, where it is warm and peaceful. " +
"Perhaps when I return I'll get around to reading your mail. " +
"Or perhaps not.";
/* The text/html data. */
protected String html_data =
"<HTML><HEAD><TITLE>My Goodness</TITLE></HEAD>" +
"<BODY><P>You <EM>do</EM> look a little " +
"<font color=green>GREEN</FONT>" +
"around the edges..." +
"</BODY></HTML>";

/** The JavaMail session object */
protected Session session;
/** The JavaMail message object */
protected Message mesg;

/** Do the work: send the mail to the SMTP server. */
public void doSend() throws IOException, MessagingException {

// We need to pass info to the mail server as a Properties, since
// JavaMail (wisely) allows room for LOTS of properties...
Properties props = new Properties();
props.put("mail.smtp.host", "www.gmail.com");

// Copy the value of Mail.send.host into mail.smtp.host
// props.setProperty("mail.smtp.host",
//props.getProperty(MailConstants.SEND_HOST));

// Create the Session object
session = Session.getDefaultInstance(props, null);
session.setDebug(true); // Verbose!

try {
// create a message
mesg = new MimeMessage(session);

// From Address - this should come from a Properties...
mesg.setFrom(new InternetAddress("madhan1979@gmail.com"));

// TO Address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);

// CC Address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);

// The Subject
mesg.setSubject(message_subject);

// Now the message body.
Multipart mp = new MimeMultipart();

BodyPart textPart = new MimeBodyPart();
textPart.setText(message_body); // sets type to "text/plain"

BodyPart pixPart = new MimeBodyPart();
pixPart.setContent(html_data, "text/html");

// Collect the Parts into the MultiPart
mp.addBodyPart(textPart);
mp.addBodyPart(pixPart);

// Put the MultiPart into the Message
mesg.setContent(mp);

// Finally, send the message!
Transport.send(mesg);

} catch (MessagingException ex) {
System.err.println(ex);
ex.printStackTrace(System.err);
}
}

/** Simple test case driver */
public static void main(String[] av) throws Exception {
SendMime sm = new SendMime();
sm.doSend();
}
}


If i execute the sample code above i get the following error:

DEBUG: setDebug: JavaMail version 1.4.4
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "www.gmail.com", port 25, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: www.gmail.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
javax.mail.MessagingException: Could not connect to SMTP host: www.gmail.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at SendMime.doSend(SendMime.java:104)
at SendMime.main(SendMime.java:115)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:288)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:231)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1900)
... 8 more


Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
www.gmail.com looks like the name of a web server, not an SMTP server. Start learning how to use JavaMail with Gmail at http://www.oracle.com/technetwork/java/faq-135477.html#gmail
madhankumar kumaravelu
Greenhorn

Joined: Nov 30, 2011
Posts: 17
Sure, I will look in to it..

Hope Apache James Mail Server can be used for real time project (i.e. capable of sending mails to any external mail server not
just gmail)?

Thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Not sure how the requirements you mentioned have anything to do with real-time scenarios, but unless you're using a special JVM no Java code is suitable for real-time use.

James implements SMTP, so it can communicate with any other standards-compliant SMTP server. If you're serious about using email in your applications you should read up on mail protocols like SMTP (in particular), POP3 and IMAP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automated Mail Using Java,Apache Tomcat and Postgre,Quartz Scheduler?
 
Similar Threads
Java Mail - Struts,Hibernate,postgre,quartz scheduler?
.NET 3.5 CMM5
Testers wanted for a new Form-mail servlet
Registration id for beta results
sofware design patterns