Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

sendmail

  Asked By: Charlie    Date: Sep 15    Category: Java    Views: 561
  

i want to send Email automatically to my app user via servlet. can
anybody introduce for me java package that do this work?

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Aalia Arain     Answered On: Sep 15

You may utilize AspectJ in your application.
I can't help you any further on how to configure and setting it up

 
Answer #2    Answered By: Terence Mitchell     Answered On: Sep 15

You can use JavaMail API to quench your desire.

 
Answer #3    Answered By: Adalwin Fischer     Answered On: Sep 15

He pointed out that he wants to send  email AUTOMATICALLY and JavaMail doesn't support
such feature individually, so the answer is AspectJ

 
Answer #4    Answered By: Skye Hughes     Answered On: Sep 15

I noticed to this point but if he wanna send  mail with pure java  he can use JavaMail API like this :


import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.*;

public class MailSender {
public void postMail(String smtpsrv, String recipients[], String subject,
String message, String from) throws MessagingException {
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", smtpsrv);

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress addressTo[]= new InternetAddress[recipients.length];
addressTo= new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo= new InternetAddress(recipients);
}
msg.setRecipients(Message.RecipientType.TO,addressTo);

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/html;charset=utf-8");
Transport.send(msg);
}

}

But if he has Application Server , he could use application Server Mail Configuration to send mail automatically  also Web Server like : JBossMail, ...
And also to use AOP Concept to send mail he can use AspectJ, AspectWerks and JBossAOP too.

 
Answer #5    Answered By: Funsani Chalthoum     Answered On: Sep 15

i assume that u have any application server , like Tomcat Or Jboss .
in either of them u can define your servlet  inside web.xml file as below :


<servlet>
<servlet-name>SchadulerServlet</servlet-name>
<servlet-class>schaduler.SchadulerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SchadulerServlet</servlet-name>
<url-pattern>/US</url-pattern>
</servlet-mapping>

this part of above code <load-on-startup>1</load-on-startup> will be cause the servlet class i.e SchadulerServlet starts whenever the app  server get started.

inside the class you can define the Schaduler like Quartz that pass the mails addresses to the mail server in periodic format.
u can user  the mail server like JAMES , this is an Apache product , you can download it from Apache site.it works on port no 25 .
any more question u can ask me .

 
Answer #6    Answered By: Randall Franklin     Answered On: Sep 15

you can use JavaMail API for sending mail
but the better approach is apache common email  component which is
simple abstract API on java  mail,
if you need a scheduling system that automatically send  mail you can use
scheduling framework such as Quartz and if you want to send mail
automatically based on some action you can use aspect frameworks.

http://commons.apache.org/email/

 
Didn't find what you were looking for? Find more on sendmail Or get search suggestion and latest updates.




Tagged: