Jump to content

Help Sending Email Automatically


dzhax

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...