Tuesday, September 28, 2010

Re: Sending mails from GWT-App

He meant it isn't a GWT issue. The code you are trying to make work
has nothing to do with GWT other than it is being referenced from the
server-side code compiled by your GWT app. That said, here's some code
I use to send emails:

<pre>
try {
Session mailSession =
Session.getDefaultInstance(getProperties(hostRow));

Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);

String body = emailRow.getBodyText();

message.setSubject(emailRow.getTheme());
message.setContent(body, "text/plain");

message.addRecipient(RecipientType.TO,
new InternetAddress(userRow.getEmail()));

transport.connect(hostRow.getHostName(), hostRow.getHostPort(),
hostRow.getAuthUser(), hostRow.getAuthPass());

transport.sendMessage(message,
message.getRecipients(RecipientType.TO));

transport.close();
} catch (Throwable caught) {
throw new Exception(caught.getMessage());
}
</pre>

HTH,
Chad

On Sep 28, 8:20 am, newnoise <tommmuel...@googlemail.com> wrote:
> What does that mean?
>
> On 28 Sep., 15:12, Paul Grenyer <paul.gren...@gmail.com> wrote:
>
>
>
> > Hi
>
> > This isn't a GET issue....
>
> > Paul
>
> > On Tue, Sep 28, 2010 at 1:46 PM, newnoise <tommmuel...@googlemail.com>wrote:
>
> > > Hi,
>
> > > I'm trying to send an email from my GWT-App. I found the following
> > > code using google:
> > > protected void sendMessage(String smtpHost, String fromAddress, String
> > > fromName, String to, String subject, String text) {
> > > // Get system properties Properties
> > > props = System.getProperties();
> > > // Setup mail server
> > > props.put("mail.smtp.host", smtpHost);
> > > // Get session
> > > Session session = Session.getDefaultInstance(props, null);
> > > // Define message
> > > MimeMessage message = new MimeMessage(session);
> > > // Set the from address
> > > message.setFrom(new InternetAddress(fromAddress, fromName));
> > > // Set the to address
> > > message.addRecipient(Message.RecipientType.TO, new
> > > InternetAddress(to));
> > > // Set the subject
> > > message.setSubject(subject);
> > > // Set the content
> > > message.setContent(text, "text/html");
> > > // Send message
> > > Transport.send(message);
> > > }
>
> > > But I'm getting a "java.lang.AssertionError: null".
>
> > > I was wondering why I do not have to enter a password for the smtp-
> > > server, and what to enter at String smtpHost, as I have to enter my
> > > Smtp-Host at props.put() again ...
>
> > > Thanks!
> > > Tom
>
> > > --
> > > 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+unsubscribe@googlegroups.com<google-web-toolkit%2Bunsubs cribe@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> > --
> > Thanks
> > Paul
>
> > Paul Grenyer
> > e: paul.gren...@gmail.com
> > b: paulgrenyer.blogspot.com
> > t: pjgrenyer

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment