You could use this example as a reference. http://code.google.com/p/gwtupload/source/browse/#svn/trunk/SendMailSample/src/main/java/gwtupload/sendmailsample
svn checkout http://gwtupload.googlecode.com/svn/trunk/SendMailSample Cheers -Manolo On Mon, May 10, 2010 at 7:06 AM, abhiram wuntakal <abhir...@gmail.com> wrote: > Hi Felipe, > > This block of code would help you send an email from the application. The > trick basically is to get the textual data from the client side and pass it > to the server side and then use this piece of code to send the email. This > is actually with the file attachment feature even. > > Initially, you need to have a few variables declared for the username, > password, SMTP etc... > > private static String SMTP_HOST_NAME = "abc-abc.abc.com"; > private static String SMTP_AUTH_USER = "a...@abc.com"; > private static String SMTP_AUTH_PWD = "abcpassword"; > private static final String emailMsgTxt = "Sample Message - Testing the > email application"; > private static final String emailSubjectTxt = "Sample Mail"; > private static String emailFromAddress = "ab...@abcde.com"; > private static final String[] emailList = new String[100]; > String fileAttachment = SRCFOLDER + "sample.pdf"; > > public void sendEmail(EmailDetailsVo emailVo) { > emailList[0] = emailVo.getEmailRecipient(); > Writer output = null; > String text = "sample Text"; > OutputStream file; > System.out.println("Inside send email2"); > > fileAttachment = SRCFOLDER + "sample.pdf"; > > try { > file = new FileOutputStream( > new File( > SRCFOLDER + "sample.pdf")); > > Document document = new Document(); > try { > PdfWriter.getInstance(document, file); > document.open(); > document.add(new Paragraph(String_Body_Of_The_Email)); > > } catch (DocumentException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > document.close(); > try { > file.close(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > } catch (FileNotFoundException e1) { > // TODO Auto-generated catch block > e1.printStackTrace(); > } > > Properties props = new Properties(); > props.put("mail.transport.protocol", "smtp"); > props.put("mail.smtp.starttls.enable", "true"); > props.put("mail.smtp.host", SMTP_HOST_NAME); > props.put("mail.smtp.auth", "true"); > > Authenticator auth = new SMTPAuthenticator(); > Session session = Session.getDefaultInstance(props, auth); > MimeMessage message1 = new MimeMessage(session); > try { > message1.setFrom(new InternetAddress(emailFromAddress)); > message1.addRecipient(Message.RecipientType.TO, > new InternetAddress(emailList[0])); > message1.setSubject(emailVo.getEmailSubject()); > message1.addRecipient(Message.RecipientType.CC, > new InternetAddress(emailVo.getCcEmailAddress())); > // create the message part > MimeBodyPart messageBodyPart = new MimeBodyPart(); > > // fill message > messageBodyPart.setText(emailVo.getEmailBody()); > > Multipart multipart = new MimeMultipart(); > multipart.addBodyPart(messageBodyPart); > messageBodyPart = new MimeBodyPart(); > > DataSource source = new FileDataSource(fileAttachment); > messageBodyPart.setDataHandler(new DataHandler(source)); > messageBodyPart.setFileName("MainPdf.pdf"); > multipart.addBodyPart(messageBodyPart); > // Put parts in message > > message1.setContent(multipart); > // Send the message > Transport.send(message1); > > } catch (AddressException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (MessagingException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > // return null; > > } > > public class SMTPAuthenticator extends javax.mail.Authenticator { > > public PasswordAuthentication getPasswordAuthentication() { > String username = SMTP_AUTH_USER; > String password = SMTP_AUTH_PWD; > return new PasswordAuthentication(username, password); > } > } > > HTH, > > Thanks and Regards, > Abhiram > > On Mon, May 10, 2010 at 3:59 AM, Felipe Guarda <felip...@gmail.com> wrote: >> >> I'm trying to learn how to send emails using gwt/rpc but I have >> difficulties. >> Someone could send me a simple example that shows the implementation >> of the code on the client and server? >> >> tks >> >> -- >> 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-tool...@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. >> > > -- > 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-tool...@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. > -- 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-tool...@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.