[Building Sakai] How to send a email?
Steve Swinsburg
steve.swinsburg at gmail.com
Mon Nov 30 19:04:08 PST 2009
If you want to do it from the Web Services, you'll need to use the ComponentManager:
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.email.api.EmailService;
Create an instance var and class constructor:
private EmailService emailService;
public SakaiScript() {
emailService = (EmailService) ComponentManager.get(EmailService());
}
use it:
emailService.xxx();
I'm (eventually) going to convert the web services over to use the other API's like this so we can get rid of the static covers.
cheers,
Steve
On 01/12/2009, at 1:43 PM, Sam Chow wrote:
>
> Thanks Steve.
>
> It is very helpful, but I cannot find the component.xml in web services.
>
> Thanks
>
>
> Steve Swinsburg-3 wrote:
>>
>> Hi Sam,
>>
>> Once you have the dependecy setup in your POM, then you can inject the API
>> via your Spring config and a Javabean style setter in your implementation.
>>
>> in components.xml
>>
>> <bean id="yourbean">
>> ...
>> <property name="emailService"><ref
>> bean="org.sakaiproject.email.api.EmailService"/></property>
>> ...
>> </bean>
>>
>> in your impl:
>> private EmailService emailService;
>> public void setEmailService(EmailService emailService) {
>> this.emailService = emailService;
>> }
>>
>> then do something like:
>> emailService.sendToUsers(receivers, getHeaders(user.getEmail(), subject),
>> formatMessage(subject, message));
>> to actually send the email.
>>
>> If any of that is foreign, take a look at the code generated in a sample
>> app via the Sakai App Builder in Eclipse, or take a look at the
>> Programmers Cafe docs in Confluence, there are some code examples.
>>
>> Make sure you have the SMTP properties setup in sakai.properties too.
>>
>> cheers,
>> Steve
>>
>>
>> On 30/11/2009, at 3:21 PM, Sam Chow wrote:
>>
>>>
>>> Dear David,
>>>
>>> Thanks for your information. Actually, i am still not successful to use
>>> to
>>> api to send email.
>>>
>>> Is it possible if i copy some code from mailtool.processSendEmail to web
>>> service for this my purpose?
>>>
>>> Thanks.
>>>
>>>
>>>
>>> David Horwitz wrote:
>>>>
>>>> Hi Sam,
>>>>
>>>> You need to add the email API to your maven dependencies - seing you
>>>> need to do this I presume your using Sakai 2.5 or earlier so add this to
>>>> the dependencies of your maven pom.xml:
>>>>
>>>> <dependency>
>>>> <groupId>org.sakaiproject</grouipId>
>>>> <artifactId>sakai-email-api<artifactId>
>>>> </dependency>
>>>>
>>>> If your using Sakai 2.6 or later the dependency you need is to the
>>>> kernel api (group= org.sakaiproject.kernel artifact= kernel-api)
>>>>
>>>> David
>>>>
>>>> On 11/27/2009 08:25 AM, Sam Chow wrote:
>>>>> Dear David,
>>>>>
>>>>> it will have compilation error if i import
>>>>> org.sakaiproject.email.api.EmailService;
>>>>>
>>>>> What should i do, thanks!
>>>>>
>>>>>
>>>>>
>>>>> David Horwitz wrote:
>>>>>
>>>>>> Hi Sam,
>>>>>>
>>>>>> see the EmailService:
>>>>>> http://source.sakaiproject.org/release/kernel/1.1.0-beta03/apidocs/org/sakaiproject/email/api/EmailService.html
>>>>>>
>>>>>> D
>>>>>>
>>>>>> On 11/24/2009 10:16 AM, Sam Chow wrote:
>>>>>>
>>>>>>> Dear All,
>>>>>>>
>>>>>>> I have already written a script to upload some user information to
>>>>>>> sakai
>>>>>>> with a random password. Now, i want to email the information message
>>>>>>> to
>>>>>>> the user automatcally after his informaiton is inserted to the Sakai.
>>>>>>> Is
>>>>>>> there any email api i can call.
>>>>>>>
>>>>>>> Many Thanks!
>>>>>>>
>>>>>>> Sam
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> sakai-dev mailing list
>>>>>>> sakai-dev at collab.sakaiproject.org
>>>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>>
>>>>>>> TO UNSUBSCRIBE: send email to
>>>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>>>>>> "unsubscribe"
>>>>>>>
>>>>>> _______________________________________________
>>>>>> sakai-dev mailing list
>>>>>> sakai-dev at collab.sakaiproject.org
>>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>
>>>>>> TO UNSUBSCRIBE: send email to
>>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>>>>> "unsubscribe"
>>>>>>
>>>>>>
>>>>>
>>>> _______________________________________________
>>>> sakai-dev mailing list
>>>> sakai-dev at collab.sakaiproject.org
>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>
>>>> TO UNSUBSCRIBE: send email to
>>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>>> "unsubscribe"
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/-Building-Sakai--How-to-send-a-email--tp26492029p26569429.html
>>> Sent from the Sakai - Development mailing list archive at Nabble.com.
>>>
>>> _______________________________________________
>>> sakai-dev mailing list
>>> sakai-dev at collab.sakaiproject.org
>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>
>>> TO UNSUBSCRIBE: send email to
>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>> "unsubscribe"
>>
>>
>> _______________________________________________
>> sakai-dev mailing list
>> sakai-dev at collab.sakaiproject.org
>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>
>> TO UNSUBSCRIBE: send email to
>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>> "unsubscribe"
>>
>
> --
> View this message in context: http://old.nabble.com/-Building-Sakai--How-to-send-a-email--tp26492029p26585678.html
> Sent from the Sakai - Development mailing list archive at Nabble.com.
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"
More information about the sakai-dev
mailing list