File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Email generator

 
Mahesh Lohi
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic