Hi Graham, The browser cannot send emails but the server can. web-toolkit is the client half (and this forum), appengine can be the server half javax.mail is not supported on the client but it supported on the appengine server.
If you are using appengine to host the server portion, below is a simple email sending method that works for me. This will send email from google's appengine's mail servers. One caveat is that the FROM_ADDRESS needs to be listed as an administrator of the app. Another caveat is that Transport.send() can take a long time and may likely fail with a MessagingException. A third caveat is that bounces are eaten up due to some strange configurations in the mail servers. private static final String SUBJECT = "Thanks for..."; private static final String BODY = "Dear <to_name>..."; private static final String FROM_ADDRESS = "[email protected]"; private static final String FROM_NAME = "My Name"; private static final String BCC_ADDRESS = "[email protected]"; private boolean sendEmail( String toName, String emailAddress ) { Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); String subject = SUBJECT.replace( "<to_name>", toName ).replace( "<email_address>", emailAddress ); String body = BODY.replace( "<to_name>", toName ).replace( "<email_address>", emailAddress );; try { //-------------------------------- Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress( FROM_ADDRESS, FROM_NAME )); msg.addRecipient(Message.RecipientType.TO, new InternetAddress( emailAddress, toName )); if ( !BCC_ADDRESS.isEmpty() ) { msg.addRecipient( Message.RecipientType.BCC, new InternetAddress( BCC_ADDRESS )); } msg.setSubject(subject); msg.setText( body ); Transport.send(msg); return true; On Mon, Feb 28, 2011 at 6:27 PM, Graham Haroldson <[email protected]>wrote: > Again, im not quite sure what im trying to send emails from, i can > probably use my email, which is a gmail account. I tried that and i also > tried adding my account and password to the properties but it still does > nothing > > > > On Mon, Feb 28, 2011 at 3:04 PM, Greg Dougherty < > [email protected]> wrote: > >> > When i GWT Compile i get no errors at all. >> >> GWT Compile is client side. What you're doing is done, and can only >> be done, on the server. Where are you trying to send the mail from? >> >> Greg >> >> On Feb 28, 4:28 pm, GrahamH <[email protected]> wrote: >> > 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(" >> [email protected]"); >> > 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 [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/google-web-toolkit?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > -- -- A. Stevko =========== "If everything seems under control, you're just not going fast enough." M. Andretti -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
