geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Petersson <>
Subject Re: Mailing from geronimo
Date Sat, 30 Sep 2006 10:46:48 GMT
Okey here comes the plans and a code snippet illustrating what im trying 
to do when i get the
javax.mail.NoSuchProviderException: Unable to locate provider for 
protocol: smtp
       at javax.mail.Session.getProvider(
       at javax.mail.Session.getTransport(

Anny suggestions ?

The execute method below hass the intresting mailing part (its a bit 
messy as I have tryed diffrent approaches
Code snippet:
public class UsedAllotmentSendJob implements Job {

    private final static Log logger = 
    private DataSource dataSource;
    private Session mailSession;

    public void setDatabase(DataSource ds) {
        dataSource = ds;

    public void setMailSession(Session s) {
        mailSession = s;
    public void execute(JobExecutionContext jobcontext) throws 
JobExecutionException {
        //trying with added autentication
        String smtphost="thednsaddress";
        String username="thelogginname";
        String password="thelogginpassword";
        Message message = new MimeMessage(mailSession);
        InternetAddress from = new InternetAddress("the_sender_addr");
        InternetAddress to = new InternetAddress("the_resiver_addr");

        String mailer = "smtpsend";
        message.setHeader("X-Mailer", mailer);
        message.setSentDate(new Date());
        message.addRecipient(Message.RecipientType.TO, to);
        message.setSubject("The subject");
        message.setText("The message");
        Transport tr = mailSession.getTransport("smtp");
        tr.connect(smtphost, username, password);
        //tr.connect(); //no extra params just the gbean settings 
        message.saveChanges(); // don't forget this
        tr.sendMessage(message, message.getAllRecipients());
        //replaced with the settup above

        }catch(AddressException aex){
            logger.error("execute got a AddressException 
        }catch(MessagingException mex){
            logger.error("execute got a MessagingException 

Geronimo Quartz Plan

<?xml version="1.0" encoding="UTF-8"?>
<jobs xmlns="">
    <environment xmlns="">
        <job-name>Job name</job-name>
        <job-class>classpath to jobb class</job-class>
        <cron-expression>0/30 * * * * ?</cron-expression>

The "mail-server" plan (slightly moddyfied version of what I got from Rick):

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="">
 <gbean name="SMTPTransport" 
   <attribute name="host">removed dns name</attribute>
   <attribute name="port">25</attribute>
 <gbean name="mail/MailSession" class="org.apache.geronimo.mail.MailGBean">
   <attribute name="transportProtocol">smtp</attribute>
   <attribute name="debug">true</attribute>
   <reference name="Protocols">

Peter Petersson skrev:
> It is a remote SMTP server (in our lan) and autentication shuld not be 
> needed from inside our LAN (I have sucsessfully accessed the SMTP 
> server from within a vanila tomcat5 web app without autentication).
> Could a autentication faliur result in a NoSuchProviderException ?
> I have tryed setting the Transport attributes (smtphost, username, 
> password) from within the code
> Transport tr = mailSession.getTransport("smtp");
> tr.connect(smtphost, username, password);
> and also tryed a GBean via the attributes (host,port).
> The Gbean is from a sligtly moddified version of the "example mail 
> session" that Rick posted (he did a farly good shoot from the hip ;)).
> I but regardles of a lott of testing with different setups i still get
> javax.mail.NoSuchProviderException: Unable to locate provider for 
> protocol: smtp
>        at javax.mail.Session.getProvider(
>        at javax.mail.Session.getTransport(
> Im testing this on a fresh install of Geronimo 1.1.1
> Anny suggestions ?
> Cheers
>   Peter
> Aaron Mulder skrev:
>> Does your localhost have a mail server running?  Or are you trying to
>> send through a remote SMTP server?  Is the mail server open or do you
>> need to authenticate to it?
>> Thanks,
>>     Aaron
>> On 9/29/06, Peter Petersson <> wrote:
>>> Hi all!
>>> I quite new to Geronimo (using 1.1.1) and have some problems geting 
>>> mail
>>> to work from a geronimo-quartz job.
>>> As I understand it I need to set up a gbean or do some other
>>> configuration for javamail to work (?).
>>> The example i have folowed for the Quartz Scheduler Plugin over at
>>> have a nice setup including mailing 
>>> (in
>>> the "Deployable Jobs Example" section) but it dose not go into details
>>> on howto set up mailing (its not the scope of the example).
>>> What do I need to do to get it to work? as it is now i get this 
>>> exception
>>> MessagingException Unable to locate provider for protocol: smtp
>>> Anny good pointer out there to get mailing working in Geronimo ?
>>> Cheers
>>>   Peter

View raw message