Jump to content
Sign in to follow this  
dzhax

Help Sending Email Automatically

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...