Hi all,

Im trying to set up my GWT app so that it can send emails.

I have the code to send the email in a server-side servlet class.  I
have downloaded the Java Mail API and the JAF and included both the
mail.jar and the activation.jar files to the external jars.

Here is my Code:

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.activation.*;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import cs.ubc.ca.cs310.HockeyPool.client.EmailService;

public class EmailServiceImpl extends RemoteServiceServlet implements
EmailService  {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public void sendEmail(String email){
                Properties props = System.getProperties();
                props.put("mail.smtp.host", "smtp.gmail.com");
                props.put("mail.smtp.port", "465");

                Session mailSession = Session.getDefaultInstance(props);
                Message simpleMessage = new MimeMessage(mailSession);

                InternetAddress fromAddress = null;
                InternetAddress toAddress = null;
                try {
                        fromAddress = new 
InternetAddress("gharold...@gmail.com");
                        toAddress = new InternetAddress(email);
                } catch (AddressException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

                try {
                        simpleMessage.setFrom(fromAddress);
                        simpleMessage.setRecipient(RecipientType.TO, toAddress);
                        simpleMessage.setSubject("HockeyPool PoolAdmin 
Invitation");
                        simpleMessage.setText("Hello,<br /><br />You have been 
added as a
Pool Administrator for our Hockey Pool System");

                        Transport.send(simpleMessage);
                        System.out.println("email sent");
                } catch (MessagingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}

When i GWT Compile i get no errors at all.
Even when i debug the program it executes all of this code just fine
and never hits an exception but the email is NEVER sent.

Another thing is every single post about using Java Mail tells me i
need the activation.jar but the following line gives me a warning that
the activiation is never used anywhere in my class

import javax.activation.*;

Any help is much appreciated
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to