| Problems sending simple emails [message #333090] | 
Tue, 25 November 2008 10:23   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 10:26   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
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 
>
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.03522 seconds