• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Email generator

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic