Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Problems sending simple emails
Problems sending simple emails [message #333090] Tue, 25 November 2008 15:23 Go to next message
James Sundra is currently offline James SundraFriend
Messages: 1
Registered: July 2009
Junior Member
First I'll admit I'm not 100% sure this is the right place for this
message.

Anyhow, what I'm trying to do is create a program that will send an email
to one source. Many of the examples I've found online are more complex,
allowing you to pass arguments for the to, from, and host. The simplest
one i found is this:

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

// Send a simple, single part, text/plain e-mail
public class TestEmail {

public static void main(String[] args) {

// SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
String to = "vipan@vipan.com";
String from = "vipan@vipan.com";
// SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
String host = "smtp.yourisp.net";

// Create properties, get Session
Properties props = new Properties();

// If using static Transport.send(),
// need to specify which host to send it to
props.put("mail.smtp.host", host);
// To see what is going on behind the scene
props.put("mail.debug", "true");
Session session = Session.getInstance(props);

try {
// Instantiatee a message
Message msg = new MimeMessage(session);

//Set message attributes
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test E-Mail through Java");
msg.setSentDate(new Date());

// Set message content
msg.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.");

//Send the message
Transport.send(msg);
}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
mex.printStackTrace();
}
}
}//End of class

This code can be found at http://www.vipan.com/htdocs/javamail.html.

When I went to use this, i changed the to, from, and host variables to
match my data and when i test the code their are no errors and it seems
like the program runs fine but i never receive an email. I'm not sure if I
have to put my host at: props.put("mail.smtp.host", host); and i tried it
with the default data and with my host, but neither work.

If anyone has suggestions on what to do or an easy way to send emails
advice is greatly appreciated

Thanks In Advance,
James
Re: Problems sending simple emails [message #333092 is a reply to message #333090] Tue, 25 November 2008 15:26 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Try asking at the Sun-Java newsgroups because this is a general mail-API
problem and has no relevance to eclipse.

Tom

James Sundra schrieb:
> First I'll admit I'm not 100% sure this is the right place for this
> message.
>
> Anyhow, what I'm trying to do is create a program that will send an
> email to one source. Many of the examples I've found online are more
> complex, allowing you to pass arguments for the to, from, and host. The
> simplest one i found is this:
>
> import java.util.*;
> import javax.mail.*;
> import javax.mail.internet.*;
> import javax.activation.*;
>
> // Send a simple, single part, text/plain e-mail
> public class TestEmail {
>
> public static void main(String[] args) {
>
> // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
> String to = "vipan@vipan.com";
> String from = "vipan@vipan.com";
> // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
> String host = "smtp.yourisp.net";
>
> // Create properties, get Session
> Properties props = new Properties();
>
> // If using static Transport.send(),
> // need to specify which host to send it to
> props.put("mail.smtp.host", host);
> // To see what is going on behind the scene
> props.put("mail.debug", "true");
> Session session = Session.getInstance(props);
>
> try {
> // Instantiatee a message
> Message msg = new MimeMessage(session);
>
> //Set message attributes
> msg.setFrom(new InternetAddress(from));
> InternetAddress[] address = {new InternetAddress(to)};
> msg.setRecipients(Message.RecipientType.TO, address);
> msg.setSubject("Test E-Mail through Java");
> msg.setSentDate(new Date());
>
> // Set message content
> msg.setText("This is a test of sending a " +
> "plain text e-mail through Java.\n" +
> "Here is line 2.");
>
> //Send the message
> Transport.send(msg);
> }
> catch (MessagingException mex) {
> // Prints all nested (chained) exceptions as well
> mex.printStackTrace();
> }
> }
> }//End of class
>
> This code can be found at http://www.vipan.com/htdocs/javamail.html.
> When I went to use this, i changed the to, from, and host variables to
> match my data and when i test the code their are no errors and it seems
> like the program runs fine but i never receive an email. I'm not sure if
> I have to put my host at: props.put("mail.smtp.host", host); and i tried
> it with the default data and with my host, but neither work.
>
> If anyone has suggestions on what to do or an easy way to send emails
> advice is greatly appreciated
>
> Thanks In Advance,
> James
>
Previous Topic:FormColors does not provide a way to destroy a color in 3.4
Next Topic:disable "Show All Wizards" check box when using activities
Goto Forum:
  


Current Time: Sat Nov 02 17:07:40 GMT 2024

Powered by FUDForum. Page generated in 0.03378 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top