wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes Email generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Email generator" Watch "Email generator" New topic
Author

Email generator

Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
Hi all,

I would like to use a automated email generator (ie we get email to our email id each time we get a reply to a query).

I am badly in need of it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
Bear Bibeault wrote:Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.



Sorry for that, thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41106
    
  45
The Java API for sending email is called JavaMail. The http://faq.javaranch.com/java/JavaEnterpriseEditionFaq has some links to introductions and other material about it. Note that you'll need an email server to use it (or use a library like Aspirin that can send email w/o a mail server).


Ping & DNS - my free Android networking tools app
Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
Ulf Dittmer wrote:The Java API for sending email is called JavaMail. The http://faq.javaranch.com/java/JavaEnterpriseEditionFaq has some links to introductions and other material about it. Note that you'll need an email server to use it (or use a library like Aspirin that can send email w/o a mail server).


Thank you
mih ira
Greenhorn

Joined: Sep 30, 2008
Posts: 10
This is the sample code for your request


Use this for sending your emails automatically

try {
SendEmail sendEmail = new SendEmail();
String[] sendEmails = this.getUsersEmails();

String subject = "This is email subject";
String description = "email body message";
String userMail = getLoggedInUser();

sendEmail.postMail(
sendEmails,
subject,
description,
userMail);


} catch (MessagingException ex) {
ex.printStackTrace();
}



//SendEmail.java class method

public void postMail( 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", "email server ip address");

// 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];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);


// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "Write here the email header");


// Setting the Subject and Content Type
msg.setSubject(subject);
/*msg.setContent(message, "text/plain");*/




// Create a message part to represent the body text
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(message);

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
//msg.setContent(message, "text/plain");


Transport.send(msg);
}

mihira
Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
mih ira wrote: This is the sample code for your request


Use this for sending your emails automatically

try {
SendEmail sendEmail = new SendEmail();
String[] sendEmails = this.getUsersEmails();

String subject = "This is email subject";
String description = "email body message";
String userMail = getLoggedInUser();

sendEmail.postMail(
sendEmails,
subject,
description,
userMail);


} catch (MessagingException ex) {
ex.printStackTrace();
}



//SendEmail.java class method

public void postMail( 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", "email server ip address");

// 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];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);


// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "Write here the email header");


// Setting the Subject and Content Type
msg.setSubject(subject);
/*msg.setContent(message, "text/plain");*/




// Create a message part to represent the body text
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(message);

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
msg.setContent(multipart);
//msg.setContent(message, "text/plain");


Transport.send(msg);
}


Thank you for the reply

"email server ip address"
What is the ip

Thank you in advance

mih ira
Greenhorn

Joined: Sep 30, 2008
Posts: 10
It is the mail server IP.
You have to give the mail server IP address and open the ports for email send.
Mahesh Lohi
Ranch Hand

Joined: Jun 22, 2009
Posts: 150
mih ira wrote:It is the mail server IP.
You have to give the mail server IP address and open the ports for email send.



Thank you for the quick reply.

I am new to this technology. Please explain further or if possible the link where I can find the answer. Hope you dont mind

Thank you in advance


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Email generator
 
Similar Threads
Size of .java file affects compiling.
Threads and Waiting for DB connection
Java Entry Level
adding more than one entry
Assigned id generator and Save Method