You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by newtonik <ne...@gmail.com> on 2009/06/18 05:01:30 UTC

ChenilleKit Mail -- How to Use? or Any Mailer?

Can anyone give me an example on how to use this 
http://www.chenillekit.org/chenillekit-mail/SmtpService.html mailer . I am
new to Tapestry and I have been trying some of their components. I decided
to try the mailer today but I don't seem to know how to get it to work. I
don't seem to know how to Inject the Service into my pages. 

Can someone point me in the right direction? 

How about what people use to mail? Does everyone basically use the Apache
Commons EMail?
-- 
View this message in context: http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24085676.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by Massimo Lusetti <ml...@gmail.com>.
On Thu, Jun 18, 2009 at 5:01 AM, newtonik <ne...@gmail.com> wrote:

>
> Can anyone give me an example on how to use this
> http://www.chenillekit.org/chenillekit-mail/SmtpService.html mailer . I am
> new to Tapestry and I have been trying some of their components. I decided
> to try the mailer today but I don't seem to know how to get it to work. I
> don't seem to know how to Inject the Service into my pages.
>
> Can someone point me in the right direction?
>
> How about what people use to mail? Does everyone basically use the Apache
> Commons EMail?

Which version of CK are you using?

--
Massimo
http://meridio.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by newtonik <ne...@gmail.com>.
It is the case...I switched to 1.0.0 and it works now. Not sure why, I did
notice they don't use the Configuration constants in Appmodule in 1.0.2

bbcooper wrote:
> 
> I am using CK 1.0.0, but I think this should not be the case.
> 
> 2009/6/19 newtonik <ne...@gmail.com>
> 
>>
>>
>> bbcooper wrote:
>> >
>> > Hope that helps. The above example also uses ConfigurationService (
>> > http://www.chenillekit.org/chenillekit-core/configuration.html) to read
>> > properties from file.
>> >
>> > Cheers,
>> > Borut
>> >
>> > 2009/6/18 newtonik <ne...@gmail.com>
>> >
>> >>
>> >> Can anyone give me an example on how to use this
>> >> http://www.chenillekit.org/chenillekit-mail/SmtpService.html mailer .
>> I
>> >> am
>> >> new to Tapestry and I have been trying some of their components. I
>> >> decided
>> >> to try the mailer today but I don't seem to know how to get it to
>> work.
>> I
>> >> don't seem to know how to Inject the Service into my pages.
>> >>
>> >> Can someone point me in the right direction?
>> >>
>> >> How about what people use to mail? Does everyone basically use the
>> Apache
>> >> Commons EMail?
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24085676.html
>> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> >> For additional commands, e-mail: users-help@tapestry.apache.org
>> >>
>> >>
>> >
>> >
>>
>> Thanks I decided to try yours. I ended up getting as close as I got using
>> one of my previous trial and error. I get this exception when I try to
>> inject the service.
>>
>> Exception constructing service 'EmailService': Error invoking constructor
>> com.team.web.services.EmailServiceImpl(SmtpService, ConfigurationService)
>> (at EmailServiceImpl.java:19) via
>> com.team.web.services.AppModule.bind(ServiceBinder) (at
>> AppModule.java:68)
>> (for service 'EmailService'): Error building service proxy for service
>> 'SimpleSmtpService' (at
>> org.chenillekit.mail.services.impl.SimpleSmtpServiceImpl(Logger,
>> ConfigurationService, Map) (at SimpleSmtpServiceImpl.java:49) via
>> org.chenillekit.mail.ChenilleKitMailModule.bind(ServiceBinder) (at
>> ChenilleKitMailModule.java:28)): Error invoking constructor
>> org.chenillekit.mail.services.impl.SimpleSmtpServiceImpl(Logger,
>> ConfigurationService, Map) (at SimpleSmtpServiceImpl.java:49) via
>> org.chenillekit.mail.ChenilleKitMailModule.bind(ServiceBinder) (at
>> ChenilleKitMailModule.java:28) (for service 'SimpleSmtpService'): 'null'
>> does not exists!
>>
>> Looking at the code, they do a bind by id with
>> bind.bind(SmtpService.class).byId("SimpleSmtpService"). I am not sure
>> where
>> the null can be fixed
>> --
>> View this message in context:
>> http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24104038.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24111955.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by Borut Bolčina <bo...@gmail.com>.
I am using CK 1.0.0, but I think this should not be the case.

2009/6/19 newtonik <ne...@gmail.com>

>
>
> bbcooper wrote:
> >
> > Hope that helps. The above example also uses ConfigurationService (
> > http://www.chenillekit.org/chenillekit-core/configuration.html) to read
> > properties from file.
> >
> > Cheers,
> > Borut
> >
> > 2009/6/18 newtonik <ne...@gmail.com>
> >
> >>
> >> Can anyone give me an example on how to use this
> >> http://www.chenillekit.org/chenillekit-mail/SmtpService.html mailer . I
> >> am
> >> new to Tapestry and I have been trying some of their components. I
> >> decided
> >> to try the mailer today but I don't seem to know how to get it to work.
> I
> >> don't seem to know how to Inject the Service into my pages.
> >>
> >> Can someone point me in the right direction?
> >>
> >> How about what people use to mail? Does everyone basically use the
> Apache
> >> Commons EMail?
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24085676.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
>
> Thanks I decided to try yours. I ended up getting as close as I got using
> one of my previous trial and error. I get this exception when I try to
> inject the service.
>
> Exception constructing service 'EmailService': Error invoking constructor
> com.team.web.services.EmailServiceImpl(SmtpService, ConfigurationService)
> (at EmailServiceImpl.java:19) via
> com.team.web.services.AppModule.bind(ServiceBinder) (at AppModule.java:68)
> (for service 'EmailService'): Error building service proxy for service
> 'SimpleSmtpService' (at
> org.chenillekit.mail.services.impl.SimpleSmtpServiceImpl(Logger,
> ConfigurationService, Map) (at SimpleSmtpServiceImpl.java:49) via
> org.chenillekit.mail.ChenilleKitMailModule.bind(ServiceBinder) (at
> ChenilleKitMailModule.java:28)): Error invoking constructor
> org.chenillekit.mail.services.impl.SimpleSmtpServiceImpl(Logger,
> ConfigurationService, Map) (at SimpleSmtpServiceImpl.java:49) via
> org.chenillekit.mail.ChenilleKitMailModule.bind(ServiceBinder) (at
> ChenilleKitMailModule.java:28) (for service 'SimpleSmtpService'): 'null'
> does not exists!
>
> Looking at the code, they do a bind by id with
> bind.bind(SmtpService.class).byId("SimpleSmtpService"). I am not sure where
> the null can be fixed
> --
> View this message in context:
> http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24104038.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by newtonik <ne...@gmail.com>.

bbcooper wrote:
> 
> Hope that helps. The above example also uses ConfigurationService (
> http://www.chenillekit.org/chenillekit-core/configuration.html) to read
> properties from file.
> 
> Cheers,
> Borut
> 
> 2009/6/18 newtonik <ne...@gmail.com>
> 
>>
>> Can anyone give me an example on how to use this
>> http://www.chenillekit.org/chenillekit-mail/SmtpService.html mailer . I
>> am
>> new to Tapestry and I have been trying some of their components. I
>> decided
>> to try the mailer today but I don't seem to know how to get it to work. I
>> don't seem to know how to Inject the Service into my pages.
>>
>> Can someone point me in the right direction?
>>
>> How about what people use to mail? Does everyone basically use the Apache
>> Commons EMail?
>> --
>> View this message in context:
>> http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24085676.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

Thanks I decided to try yours. I ended up getting as close as I got using
one of my previous trial and error. I get this exception when I try to
inject the service. 

Exception constructing service 'EmailService': Error invoking constructor
com.team.web.services.EmailServiceImpl(SmtpService, ConfigurationService)
(at EmailServiceImpl.java:19) via
com.team.web.services.AppModule.bind(ServiceBinder) (at AppModule.java:68)
(for service 'EmailService'): Error building service proxy for service
'SimpleSmtpService' (at
org.chenillekit.mail.services.impl.SimpleSmtpServiceImpl(Logger,
ConfigurationService, Map) (at SimpleSmtpServiceImpl.java:49) via
org.chenillekit.mail.ChenilleKitMailModule.bind(ServiceBinder) (at
ChenilleKitMailModule.java:28)): Error invoking constructor
org.chenillekit.mail.services.impl.SimpleSmtpServiceImpl(Logger,
ConfigurationService, Map) (at SimpleSmtpServiceImpl.java:49) via
org.chenillekit.mail.ChenilleKitMailModule.bind(ServiceBinder) (at
ChenilleKitMailModule.java:28) (for service 'SimpleSmtpService'): 'null'
does not exists!

Looking at the code, they do a bind by id with
bind.bind(SmtpService.class).byId("SimpleSmtpService"). I am not sure where
the null can be fixed
-- 
View this message in context: http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24104038.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by Borut Bolčina <bo...@gmail.com>.
Hi,

AppModule.java
============
    public static void bind(ServiceBinder binder) {
        binder.bind(EmailService.class);
    }

services/EmailService.java
===================
import org.apache.commons.mail.EmailException;

public interface EmailService {
    public void sendForgottenUsernameAndPassword(String emailTo, String
password) throws EmailException;
}

services/EmailServiceImpl.java
======================
public class EmailServiceImpl implements EmailService {
    private SmtpService smtpService;
    private Configuration configuration;

    public EmailServiceImpl(SmtpService smtpService, ConfigurationService
configurationService) {
        this.smtpService = smtpService;

        Resource configResource = new
ClasspathResource("identity-server.properties");
        this.configuration =
configurationService.getConfiguration(configResource);
    }

    public void sendForgottenUsernameAndPassword(String emailTo, String
password) throws EmailException {
        SimpleEmail email = new SimpleEmail();
        email.setCharset("utf8");
        String subject =
configuration.getString("email-forgotten-password-subject");
        email.setSubject(subject);
        email.addTo(emailTo);
        String emailFrom =
configuration.getString("email-confirm-account-from");
        email.setFrom(emailFrom);
        String message = "Plain text message.";
        email.setMsg(message);

        smtpService.sendEmail(email);

    }
}

and then in your page class:

    @Inject
    private EmailService emailService;

    void onSuccess() {
        // send email with newly generated password for the user with given
email
        String rawPassword = RandomStringUtils.randomAlphanumeric(6);
        String email = someEmail;
        try {
            emailService.sendForgottenUsernameAndPassword(email,
rawPassword);
        } catch (EmailException e) {
            logger.warn("Sending email have failed.");
        }
    }


Hope that helps. The above example also uses ConfigurationService (
http://www.chenillekit.org/chenillekit-core/configuration.html) to read
properties from file.

Cheers,
Borut

2009/6/18 newtonik <ne...@gmail.com>

>
> Can anyone give me an example on how to use this
> http://www.chenillekit.org/chenillekit-mail/SmtpService.html mailer . I am
> new to Tapestry and I have been trying some of their components. I decided
> to try the mailer today but I don't seem to know how to get it to work. I
> don't seem to know how to Inject the Service into my pages.
>
> Can someone point me in the right direction?
>
> How about what people use to mail? Does everyone basically use the Apache
> Commons EMail?
> --
> View this message in context:
> http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24085676.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by Christian Edward Gruber <ch...@gmail.com>.
I wrote an incredibly simple component that I'm using on an internal  
website.  The google-code project is here:

http://code.google.com/p/israfil-mail-service/

The usage is documented in the javadoc comments.  I'll put up some  
better usage docs later.  It's BSD licensed so it's unrestricted.

I use this in my maven pom (or you can download the jars from http://repo1.maven.org/maven2/net/israfil/services/mail/)

                 <dependency>
                         <groupId>net.israfil.services.mail</groupId>
                         <artifactId>israfil-mail-service-javamail</ 
artifactId>
                         <version>0.6</version>
                 </dependency>
                 <dependency>
                         <groupId>net.israfil.services.mail</groupId>
                         <artifactId>israfil-mail-service-api</ 
artifactId>
                         <version>0.6</version>
                 </dependency>

and then I add this to my AppModule (to get a javax.mail session from  
jetty - you have to declare it in jetty.xml, but there's a default one  
there you can modify.)

     @EagerLoad
     public static javax.mail.Session buildJavaMailSession() throws  
NamingException {
         InitialContext cxt = new InitialContext();
         javax.mail.Session session = (javax.mail.Session)  
cxt.lookup( "java:comp/env/mail/main/session" );
         if ( session == null ) {
            throw new NamingException("javax.mail.Session not found!");
         }
         return session;
     }

Since the module I include in the javamail service implementation has  
metadata for tapestry-ioc autoloading then if its in the classpath  
it's loaded.  If you're using this all from eclipse or another IDE,  
you have to lauch with - 
Dtapestry 
.modules 
=net.israfil.service.mail.transport.javamail.JavaMailTransportModule.   
 From here you can just inject the service like this in any component  
or service in Tapestry:

         @Inject
         private MailService mailService;

Then you just use the service.  Here's a simple example I use for  
internal notification.

        private MailMessage  
prepareInternalNotificationMail(Registration registration,String  
address) {
                 SMTPMessage message = new SMTPMessage();
                 message.setFromAddress(new SMTPAddress("Registration  
System","training@israfil.net"));
                 message.addAddress(SMTPHeaderTypes.To,new  
SMTPAddress(address));
                 message.setSubject(String.format("Registration for %s  
%s (%s: %s)",
                         registration.getFirstName(),
                         registration.getLastName(),
                         registration.getEvent().getCourse().getCode(),
                         registration.getEvent().getStartDate()
                 ));
		// Here I set up a string to add to the body.
                 String body = String.format(
                         "%s %s has regisered for an %s class on %s\n\n 
%s",
                         registration.getFirstName(),
                         registration.getLastName(),
                         registration.getEvent().getCourse().getCode(),
                         registration.getEvent().getStartDate(),
                         registration.getPlainText()
                 );
                 message.setBody(new PlaintextMessageBody(body));
                 return message;
         }

which I call from:

     ...
     mailService.send(prepareInternalNotificationMail(registration,  
registrationNotificationEmail);
     ...

It's pretty much as simple as that.  The annoying part is the setup,  
but this is the same for nearly any service/component you want to  
stage with Dependency Injection.

If you bother using it, and have any questions, shoot me an e-mail.   
There's no compelling advantage of mine over others necessarily,  
except that it's small, doesn't have a lot of bloat, and the API  
allows for alternate mail transport back-ends, though none are  
implemented at the moment.

cheers,
Christian.


On 17-Jun-09, at 23:01 , newtonik wrote:

>
> Can anyone give me an example on how to use this
> http://www.chenillekit.org/chenillekit-mail/SmtpService.html  
> mailer . I am
> new to Tapestry and I have been trying some of their components. I  
> decided
> to try the mailer today but I don't seem to know how to get it to  
> work. I
> don't seem to know how to Inject the Service into my pages.
>
> Can someone point me in the right direction?
>
> How about what people use to mail? Does everyone basically use the  
> Apache
> Commons EMail?
> -- 
> View this message in context: http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24085676.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

Christian Edward Gruber
e-mail: christianedwardgruber@gmail.com
weblog: http://www.geekinasuit.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: ChenilleKit Mail -- How to Use? or Any Mailer?

Posted by newtonik <ne...@gmail.com>.

P.Stavrinides wrote:
> 
> 
> Which version of CK are you using?
> 
> --
> Massimo
> http://meridio.blogspot.com
> 

I am using 1.0.2
I compared the two versions I saw, the only difference I could see was they
were the properties where retrieved. 



Thanks everyone, I will try the suggestions tonight and I am sure one will
work. 
-- 
View this message in context: http://www.nabble.com/ChenilleKit-Mail----How-to-Use--or-Any-Mailer--tp24085676p24094796.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org