this code works for me:

String smtpServer = "mailserver01";
try {
   Properties props = new Properties();
   props.put("mail.smtp.host", smtpServer);
   Session session = Session.getDefaultInstance(props);
   Message msg = new MimeMessage(session);

   InternetAddress addressFrom;
   addressFrom = new InternetAddress(from);
   msg.setFrom(addressFrom);

   InternetAddress addressTo = new InternetAddress(recipient);
   msg.setRecipient(Message.RecipientType.TO, addressTo);

   msg.setSubject(subject);
   msg.setContent(message, "text/plain");
// msg.setHeader("Content-Type", "text/plain" + (charset == null ?
"" : "; charset="+charset));
   Transport.send(msg);
} catch (Exception e) {
   System.err.println(e.getMessage()); e.printStackTrace();
}

On Oct 1, 11:27 pm, Jared Smith <[email protected]> wrote:
> Well only errors would not be caught.  However, I have revised my code to
> catch anything throwable and am not getting anything.  I also checked the
> exchange box, and the emails are not hitting it, so it has something to do
> with the appengine I suppose.  I also noticed that the javax.mail is
> included in the appengine SDK so no import is necessary to use it.
>
> Mike, are you able to get yours to send an email successfully?  If so, are
> you using the appengine sdk?  Also, are you developing the web app in
> Eclipse?
>
> On Wed, Sep 30, 2009 at 3:57 PM, charlie <[email protected]> wrote:
> > Throwable is the root exception class, so something might be getting thrown
> > you're not catching.
>
> > On Wed, Sep 30, 2009 at 3:54 PM, mikedshaffer <[email protected]>wrote:
>
> >> Your javax code looks fine (I have props.put
> >> ("mail.transport.protocol", "SMTP" ); also, but I don't recall if it's
> >> necessary).  So I'd check to see if the mail server is receiving the
> >> email.  A couple ways to do that is to turn on logging on the mail
> >> server (that's not my area of expertise but we've had to do it a time
> >> or two) and/or use a product like Wireshark to look at the traffic on
> >> the network.  To do that, you'll need console access to your GWT
> >> server...but sniffing the wire is pretty much the only way to see
> >> what's going on in javax.
>
> >> Good luck.
>
> >> On Sep 29, 3:37 pm, Jared Smith <[email protected]> wrote:
> >> > I am having a bit of an issue testing my web application.  I have
> >> written a
> >> > customized Emailer class that is used to send an email to the specified
> >> > email address.  I am able to get the class to successfully send an email
> >> > while using a driver class, however, when I attempt to use the Emailer
> >> class
> >> > on the server side, no email is sent.  I have embeded the code in a
> >> > try-catch block and I am not catching any exceptions.  Does anyone have
> >> any
> >> > knowledge as to why this may be the case?
>
> >> > Server Side Code:
>
> >> ***************************************************************************­*********************************************
> >> > /**
> >> >  * The server side implementation of the RPC service.
> >> >  */
> >> > @SuppressWarnings("serial")
> >> > public class EmailServiceImpl extends RemoteServiceServlet implements
> >> > EmailService {
> >> >     public String sendEmail(String email) {
> >> >         try {
> >> >             Emailer eMail = new Emailer();
> >> >             eMail.setEmailRecipient(email);
> >> >             eMail.setEmailSender(email);
> >> >             eMail.setEmailSubject("Its Jail!");
> >> >             eMail.setEmailText("No, java mail silly!!...");
> >> >             eMail.send();
> >> >             return "an email has successfully been sent to the specified
> >> > email address.";
> >> >         } catch(Exception e) {
> >> >             return "An exception has occured.";
> >> >         }
> >> >     }}
>
> >> ***************************************************************************­*********************************************
>
> >> > Emailer class:
>
> >> ***************************************************************************­*********************************************
> >> > import java.util.*;
> >> > import javax.mail.*;
> >> > import javax.mail.internet.*;
>
> >> > public class Emailer {
> >> >     private String smtpHost;
> >> >     private int smtpPort;
> >> >     private String emailSender;
> >> >     private String emailRecipient;
> >> >     private String emailSubject;
> >> >     private String emailText;
>
> >> >     public Emailer() {
> >> >         smtpHost = "*mysmtphost*";
> >> >         smtpPort = 25;
> >> >     }
>
> >> >     public Emailer(String host, int port) {
> >> >         smtpHost = host;
> >> >         smtpPort = port;
> >> >     }
>
> >> >     public void setEmailSender(String sender) {
> >> >         emailSender = sender;
> >> >     }
>
> >> >     public void setEmailRecipient(String recipient) {
> >> >         emailRecipient = recipient;
> >> >     }
>
> >> >     public void setEmailSubject(String subject) {
> >> >         emailSubject = subject;
> >> >     }
>
> >> >     public void setEmailText(String text) {
> >> >         emailText = text;
> >> >     }
>
> >> >     public void send() {
> >> >         Properties props = new Properties();
> >> >         props.put("mail.smtp.host", smtpHost);
> >> >         props.put("mail.smtp.port", smtpPort);
> >> >         Session ses = Session.getDefaultInstance(props, null);
> >> >         Message msg = new MimeMessage(ses);
> >> >         try {
> >> >             msg.setFrom(new InternetAddress(emailSender));
> >> >             msg.setRecipient(Message.RecipientType.TO, new
> >> > InternetAddress(emailRecipient));
> >> >             msg.setSubject(emailSubject);
> >> >             msg.setText(emailText);
> >> >             Transport.send(msg);
> >> >         } catch (MessagingException e) {
> >> >             e.printStackTrace();
> >> >         }
> >> >     }}
>
> >> ***************************************************************************­*********************************************
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to