Jump to content

Help Sending Email Automatically


dzhax
 Share

Recommended Posts

I am working on a Java program...The part I am stuck on is sending an email to me with results of variables automatically.I dont need anything to show up. Just the part that sends the email "Behind the scenes".Anyone know how this could be done? And maybe a small sample will help me understand.

Link to comment
Share on other sites

  • 2 weeks later...
Anyone have any idea? I cant find this.
Hopefully you've gotten your answer by now, but if you haven't, you would need to download the JavaMail API and, if you're not using Java SE 6, you will also need to download the JavaBeans Activation Framework. Once you've downloaded and added to your project/classpath, something like this may help:
// Send e-mail// Get system propertiesProperties properties = System.getProperties();// Setup mail serverproperties.setProperty("mail.smtp.host", "smtp.mail.yahoo.com");// Get the default Session object.Session session = Session.getDefaultInstance(properties);// Create a default MimeMessage object.MimeMessage message = new MimeMessage(session);// Set the RFC 822 "From" header field using the// value of the InternetAddress.getLocalAddress method.message.setFrom(new InternetAddress("user@yahoo.com"));// Add the given addresses to the specified recipient type.message.addRecipient(Message.RecipientType.TO, new InternetAddress("webmaster@mywebsite.com"));// Set the "Subject" header field.message.setSubject(mySubjVar);// Sets the given String as this part's content,// with a MIME type of "text/plain".message.setText(myMsgVar);// Send messageTransport.send(message);

User variables where appropriate.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...