You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by zheng hao <vo...@gmail.com> on 2008/02/20 06:10:29 UTC

about sending several emails in a batch

hi all Commons Email dev,

I found when i want to send several emails in one connection, Commons Email
doesn't help. It connects to the SMTP server per email, and it spends more
time on authentication than sending the mails themselve (most SMTP server
needs authentication). So I have to code on the javamail api directly,
something like:

        SMTPSSLTransport strans = (SMTPSSLTransport) sess.getTransport();
        strans.connect();
        int num = 1000;
        for (int i = 0; i < num; i++) {
            SMTPMessage email = createMessage(sess, num);
            strans.sendMessage(email, email.getAllRecipients());
        }
        strans.close();

In my straightforward test, it saves me 2/3 of the time. So I think it would
be nice to add this kind of function into Commons Email, to make it more
useful. My suggestion is to extract a clean bean Email, which contains all
email dependent information, e.g. TO, CC, Subject, etc, but leaves out all
host/server dependent information, e.g. authenticator, host address, host
port, etc. After that, we can still provide simple convenience method for
those who only want to send one mail every time. And it is possible to add
methods like 'addEmail' to add several mails before sending, and later on,
when it is called 'send', we can send them in one SMTP connection. Does it
useful? Thank you all.

Hao Zheng

Re: about sending several emails in a batch

Posted by zheng hao <vo...@gmail.com>.
ok. I will learn the process, because i am new to open source process. thank
you.

Hao Zheng

On Thu, Feb 21, 2008 at 12:19 AM, James Carman <ja...@carmanconsulting.com>
wrote:

> Maybe you should file a JIRA asking for an enhancement.  This sounds
> like it could be useful and not very difficult.
>
> On 2/20/08, zheng hao <vo...@gmail.com> wrote:
> > yeah, I just mean that.
> >
> > it's much like the api of javamail itself, but we can provide more
> > conventient usage than it. most important is the efficiency of sending
> mails
> > in a batch.
> >
> > On Feb 20, 2008 7:17 PM, Torsten Curdt <tc...@apache.org> wrote:
> >
> > > You mean something like this?
> > >
> > >  EmailTransmission trans = new EmailTransmission();
> > >  trans.setHostName("smtp.myserver.org");
> > >
> > >  HtmlEmail email1 = new HtmlEmail();
> > >  ...
> > >  HtmlEmail email2 = new HtmlEmail();
> > >  ...
> > >
> > >  trans.addEmail(email1);
> > >  trans.addEmail(email2);
> > >  ..
> > >  trans.send();
> > >
> > > Sounds useful to me.
> > >
> > > cheers
> > > --
> > > Torsten
> > >
> > > On 20.02.2008, at 06:10, zheng hao wrote:
> > >
> > > > hi all Commons Email dev,
> > > >
> > > > I found when i want to send several emails in one connection,
> > > > Commons Email
> > > > doesn't help. It connects to the SMTP server per email, and it
> > > > spends more
> > > > time on authentication than sending the mails themselve (most SMTP
> > > > server
> > > > needs authentication). So I have to code on the javamail api
> directly,
> > > > something like:
> > > >
> > > >         SMTPSSLTransport strans = (SMTPSSLTransport)
> > > > sess.getTransport();
> > > >         strans.connect();
> > > >         int num = 1000;
> > > >         for (int i = 0; i < num; i++) {
> > > >             SMTPMessage email = createMessage(sess, num);
> > > >             strans.sendMessage(email, email.getAllRecipients());
> > > >         }
> > > >         strans.close();
> > > >
> > > > In my straightforward test, it saves me 2/3 of the time. So I think
> > > > it would
> > > > be nice to add this kind of function into Commons Email, to make it
> > > > more
> > > > useful. My suggestion is to extract a clean bean Email, which
> > > > contains all
> > > > email dependent information, e.g. TO, CC, Subject, etc, but leaves
> > > > out all
> > > > host/server dependent information, e.g. authenticator, host
> > > > address, host
> > > > port, etc. After that, we can still provide simple convenience
> > > > method for
> > > > those who only want to send one mail every time. And it is possible
> > > > to add
> > > > methods like 'addEmail' to add several mails before sending, and
> > > > later on,
> > > > when it is called 'send', we can send them in one SMTP connection.
> > > > Does it
> > > > useful? Thank you all.
> > > >
> > > > Hao Zheng
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > > For additional commands, e-mail: dev-help@commons.apache.org
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: about sending several emails in a batch

Posted by James Carman <ja...@carmanconsulting.com>.
Maybe you should file a JIRA asking for an enhancement.  This sounds
like it could be useful and not very difficult.

On 2/20/08, zheng hao <vo...@gmail.com> wrote:
> yeah, I just mean that.
>
> it's much like the api of javamail itself, but we can provide more
> conventient usage than it. most important is the efficiency of sending mails
> in a batch.
>
> On Feb 20, 2008 7:17 PM, Torsten Curdt <tc...@apache.org> wrote:
>
> > You mean something like this?
> >
> >  EmailTransmission trans = new EmailTransmission();
> >  trans.setHostName("smtp.myserver.org");
> >
> >  HtmlEmail email1 = new HtmlEmail();
> >  ...
> >  HtmlEmail email2 = new HtmlEmail();
> >  ...
> >
> >  trans.addEmail(email1);
> >  trans.addEmail(email2);
> >  ..
> >  trans.send();
> >
> > Sounds useful to me.
> >
> > cheers
> > --
> > Torsten
> >
> > On 20.02.2008, at 06:10, zheng hao wrote:
> >
> > > hi all Commons Email dev,
> > >
> > > I found when i want to send several emails in one connection,
> > > Commons Email
> > > doesn't help. It connects to the SMTP server per email, and it
> > > spends more
> > > time on authentication than sending the mails themselve (most SMTP
> > > server
> > > needs authentication). So I have to code on the javamail api directly,
> > > something like:
> > >
> > >         SMTPSSLTransport strans = (SMTPSSLTransport)
> > > sess.getTransport();
> > >         strans.connect();
> > >         int num = 1000;
> > >         for (int i = 0; i < num; i++) {
> > >             SMTPMessage email = createMessage(sess, num);
> > >             strans.sendMessage(email, email.getAllRecipients());
> > >         }
> > >         strans.close();
> > >
> > > In my straightforward test, it saves me 2/3 of the time. So I think
> > > it would
> > > be nice to add this kind of function into Commons Email, to make it
> > > more
> > > useful. My suggestion is to extract a clean bean Email, which
> > > contains all
> > > email dependent information, e.g. TO, CC, Subject, etc, but leaves
> > > out all
> > > host/server dependent information, e.g. authenticator, host
> > > address, host
> > > port, etc. After that, we can still provide simple convenience
> > > method for
> > > those who only want to send one mail every time. And it is possible
> > > to add
> > > methods like 'addEmail' to add several mails before sending, and
> > > later on,
> > > when it is called 'send', we can send them in one SMTP connection.
> > > Does it
> > > useful? Thank you all.
> > >
> > > Hao Zheng
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: about sending several emails in a batch

Posted by zheng hao <vo...@gmail.com>.
yeah, I just mean that.

it's much like the api of javamail itself, but we can provide more
conventient usage than it. most important is the efficiency of sending mails
in a batch.

On Feb 20, 2008 7:17 PM, Torsten Curdt <tc...@apache.org> wrote:

> You mean something like this?
>
>  EmailTransmission trans = new EmailTransmission();
>  trans.setHostName("smtp.myserver.org");
>
>  HtmlEmail email1 = new HtmlEmail();
>  ...
>  HtmlEmail email2 = new HtmlEmail();
>  ...
>
>  trans.addEmail(email1);
>  trans.addEmail(email2);
>  ..
>  trans.send();
>
> Sounds useful to me.
>
> cheers
> --
> Torsten
>
> On 20.02.2008, at 06:10, zheng hao wrote:
>
> > hi all Commons Email dev,
> >
> > I found when i want to send several emails in one connection,
> > Commons Email
> > doesn't help. It connects to the SMTP server per email, and it
> > spends more
> > time on authentication than sending the mails themselve (most SMTP
> > server
> > needs authentication). So I have to code on the javamail api directly,
> > something like:
> >
> >         SMTPSSLTransport strans = (SMTPSSLTransport)
> > sess.getTransport();
> >         strans.connect();
> >         int num = 1000;
> >         for (int i = 0; i < num; i++) {
> >             SMTPMessage email = createMessage(sess, num);
> >             strans.sendMessage(email, email.getAllRecipients());
> >         }
> >         strans.close();
> >
> > In my straightforward test, it saves me 2/3 of the time. So I think
> > it would
> > be nice to add this kind of function into Commons Email, to make it
> > more
> > useful. My suggestion is to extract a clean bean Email, which
> > contains all
> > email dependent information, e.g. TO, CC, Subject, etc, but leaves
> > out all
> > host/server dependent information, e.g. authenticator, host
> > address, host
> > port, etc. After that, we can still provide simple convenience
> > method for
> > those who only want to send one mail every time. And it is possible
> > to add
> > methods like 'addEmail' to add several mails before sending, and
> > later on,
> > when it is called 'send', we can send them in one SMTP connection.
> > Does it
> > useful? Thank you all.
> >
> > Hao Zheng
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: about sending several emails in a batch

Posted by Torsten Curdt <tc...@apache.org>.
You mean something like this?

  EmailTransmission trans = new EmailTransmission();
  trans.setHostName("smtp.myserver.org");

  HtmlEmail email1 = new HtmlEmail();
  ...
  HtmlEmail email2 = new HtmlEmail();
  ...

  trans.addEmail(email1);
  trans.addEmail(email2);
  ..
  trans.send();

Sounds useful to me.

cheers
--
Torsten

On 20.02.2008, at 06:10, zheng hao wrote:

> hi all Commons Email dev,
>
> I found when i want to send several emails in one connection,  
> Commons Email
> doesn't help. It connects to the SMTP server per email, and it  
> spends more
> time on authentication than sending the mails themselve (most SMTP  
> server
> needs authentication). So I have to code on the javamail api directly,
> something like:
>
>         SMTPSSLTransport strans = (SMTPSSLTransport)  
> sess.getTransport();
>         strans.connect();
>         int num = 1000;
>         for (int i = 0; i < num; i++) {
>             SMTPMessage email = createMessage(sess, num);
>             strans.sendMessage(email, email.getAllRecipients());
>         }
>         strans.close();
>
> In my straightforward test, it saves me 2/3 of the time. So I think  
> it would
> be nice to add this kind of function into Commons Email, to make it  
> more
> useful. My suggestion is to extract a clean bean Email, which  
> contains all
> email dependent information, e.g. TO, CC, Subject, etc, but leaves  
> out all
> host/server dependent information, e.g. authenticator, host  
> address, host
> port, etc. After that, we can still provide simple convenience  
> method for
> those who only want to send one mail every time. And it is possible  
> to add
> methods like 'addEmail' to add several mails before sending, and  
> later on,
> when it is called 'send', we can send them in one SMTP connection.  
> Does it
> useful? Thank you all.
>
> Hao Zheng


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: about sending several emails in a batch

Posted by zheng hao <vo...@gmail.com>.
you mean the current implementation, I see. we mean the same idea.

On Sun, Feb 24, 2008 at 10:58 PM, Siegfried Goeschl <
siegfried.goeschl@it20one.at> wrote:

> * /**
>  * Sends the email. Internally we build a MimeMessage
>  * which is afterwards sent to the SMTP server.
>  *
>  * @return the message id of the underlying MimeMessage
>  * @throws EmailException the sending failed
>  */
>  public String send() throws EmailException
>  {
>     this.buildMimeMessage();
>     return this.sendMimeMessage();
>  }
> *
>
> Siegfried Goeschl
>
> zheng hao wrote:
> > hi,
> >
> > 1). yes, it will resemble the javamail api to a great extent. but we can
> > provide more convenient methods than the api.
> > 2). I am not clear what do you mean by ' a Email can send itself'? could
> you
> > provide some kind of code snippet?
> >
> > On Fri, Feb 22, 2008 at 3:26 PM, Siegfried Goeschl <
> > siegfried.goeschl@it20one.at> wrote:
> >
> >
> >> Hi,
> >>
> >> I have two thoughts along the line
> >>
> >> +) using the Commons Email API you get access to the underlying
> >> MimeMessage which is pretty much the "clean bean email" you are looking
> >> for
> >> +) the fact that a Email can send itself is "inversion of control" but
> >> the bad one - using some sort of transport layer based on interfaces
> >> would be nice
> >>
> >> Cheers,
> >>
> >> Siegfried Goeschl
> >>
> >> zheng hao wrote:
> >>
> >>> hi all Commons Email dev,
> >>>
> >>> I found when i want to send several emails in one connection, Commons
> >>>
> >> Email
> >>
> >>> doesn't help. It connects to the SMTP server per email, and it spends
> >>>
> >> more
> >>
> >>> time on authentication than sending the mails themselve (most SMTP
> >>>
> >> server
> >>
> >>> needs authentication). So I have to code on the javamail api directly,
> >>> something like:
> >>>
> >>>         SMTPSSLTransport strans = (SMTPSSLTransport) sess.getTransport
> >>>
> >> ();
> >>
> >>>         strans.connect();
> >>>         int num = 1000;
> >>>         for (int i = 0; i < num; i++) {
> >>>             SMTPMessage email = createMessage(sess, num);
> >>>             strans.sendMessage(email, email.getAllRecipients());
> >>>         }
> >>>         strans.close();
> >>>
> >>> In my straightforward test, it saves me 2/3 of the time. So I think it
> >>>
> >> would
> >>
> >>> be nice to add this kind of function into Commons Email, to make it
> more
> >>> useful. My suggestion is to extract a clean bean Email, which contains
> >>>
> >> all
> >>
> >>> email dependent information, e.g. TO, CC, Subject, etc, but leaves out
> >>>
> >> all
> >>
> >>> host/server dependent information, e.g. authenticator, host address,
> >>>
> >> host
> >>
> >>> port, etc. After that, we can still provide simple convenience method
> >>>
> >> for
> >>
> >>> those who only want to send one mail every time. And it is possible to
> >>>
> >> add
> >>
> >>> methods like 'addEmail' to add several mails before sending, and later
> >>>
> >> on,
> >>
> >>> when it is called 'send', we can send them in one SMTP connection.
> Does
> >>>
> >> it
> >>
> >>> useful? Thank you all.
> >>>
> >>> Hao Zheng
> >>>
> >>>
> >>>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: dev-help@commons.apache.org
> >>
> >>
> >>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: about sending several emails in a batch

Posted by Siegfried Goeschl <si...@it20one.at>.
* /**
  * Sends the email. Internally we build a MimeMessage
  * which is afterwards sent to the SMTP server.
  *
  * @return the message id of the underlying MimeMessage
  * @throws EmailException the sending failed
  */
 public String send() throws EmailException
 {
     this.buildMimeMessage();
     return this.sendMimeMessage();
 }
*

Siegfried Goeschl

zheng hao wrote:
> hi,
>
> 1). yes, it will resemble the javamail api to a great extent. but we can
> provide more convenient methods than the api.
> 2). I am not clear what do you mean by ' a Email can send itself'? could you
> provide some kind of code snippet?
>
> On Fri, Feb 22, 2008 at 3:26 PM, Siegfried Goeschl <
> siegfried.goeschl@it20one.at> wrote:
>
>   
>> Hi,
>>
>> I have two thoughts along the line
>>
>> +) using the Commons Email API you get access to the underlying
>> MimeMessage which is pretty much the "clean bean email" you are looking
>> for
>> +) the fact that a Email can send itself is "inversion of control" but
>> the bad one - using some sort of transport layer based on interfaces
>> would be nice
>>
>> Cheers,
>>
>> Siegfried Goeschl
>>
>> zheng hao wrote:
>>     
>>> hi all Commons Email dev,
>>>
>>> I found when i want to send several emails in one connection, Commons
>>>       
>> Email
>>     
>>> doesn't help. It connects to the SMTP server per email, and it spends
>>>       
>> more
>>     
>>> time on authentication than sending the mails themselve (most SMTP
>>>       
>> server
>>     
>>> needs authentication). So I have to code on the javamail api directly,
>>> something like:
>>>
>>>         SMTPSSLTransport strans = (SMTPSSLTransport) sess.getTransport
>>>       
>> ();
>>     
>>>         strans.connect();
>>>         int num = 1000;
>>>         for (int i = 0; i < num; i++) {
>>>             SMTPMessage email = createMessage(sess, num);
>>>             strans.sendMessage(email, email.getAllRecipients());
>>>         }
>>>         strans.close();
>>>
>>> In my straightforward test, it saves me 2/3 of the time. So I think it
>>>       
>> would
>>     
>>> be nice to add this kind of function into Commons Email, to make it more
>>> useful. My suggestion is to extract a clean bean Email, which contains
>>>       
>> all
>>     
>>> email dependent information, e.g. TO, CC, Subject, etc, but leaves out
>>>       
>> all
>>     
>>> host/server dependent information, e.g. authenticator, host address,
>>>       
>> host
>>     
>>> port, etc. After that, we can still provide simple convenience method
>>>       
>> for
>>     
>>> those who only want to send one mail every time. And it is possible to
>>>       
>> add
>>     
>>> methods like 'addEmail' to add several mails before sending, and later
>>>       
>> on,
>>     
>>> when it is called 'send', we can send them in one SMTP connection. Does
>>>       
>> it
>>     
>>> useful? Thank you all.
>>>
>>> Hao Zheng
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>>     
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: about sending several emails in a batch

Posted by zheng hao <vo...@gmail.com>.
hi,

1). yes, it will resemble the javamail api to a great extent. but we can
provide more convenient methods than the api.
2). I am not clear what do you mean by ' a Email can send itself'? could you
provide some kind of code snippet?

On Fri, Feb 22, 2008 at 3:26 PM, Siegfried Goeschl <
siegfried.goeschl@it20one.at> wrote:

> Hi,
>
> I have two thoughts along the line
>
> +) using the Commons Email API you get access to the underlying
> MimeMessage which is pretty much the "clean bean email" you are looking
> for
> +) the fact that a Email can send itself is "inversion of control" but
> the bad one - using some sort of transport layer based on interfaces
> would be nice
>
> Cheers,
>
> Siegfried Goeschl
>
> zheng hao wrote:
> > hi all Commons Email dev,
> >
> > I found when i want to send several emails in one connection, Commons
> Email
> > doesn't help. It connects to the SMTP server per email, and it spends
> more
> > time on authentication than sending the mails themselve (most SMTP
> server
> > needs authentication). So I have to code on the javamail api directly,
> > something like:
> >
> >         SMTPSSLTransport strans = (SMTPSSLTransport) sess.getTransport
> ();
> >         strans.connect();
> >         int num = 1000;
> >         for (int i = 0; i < num; i++) {
> >             SMTPMessage email = createMessage(sess, num);
> >             strans.sendMessage(email, email.getAllRecipients());
> >         }
> >         strans.close();
> >
> > In my straightforward test, it saves me 2/3 of the time. So I think it
> would
> > be nice to add this kind of function into Commons Email, to make it more
> > useful. My suggestion is to extract a clean bean Email, which contains
> all
> > email dependent information, e.g. TO, CC, Subject, etc, but leaves out
> all
> > host/server dependent information, e.g. authenticator, host address,
> host
> > port, etc. After that, we can still provide simple convenience method
> for
> > those who only want to send one mail every time. And it is possible to
> add
> > methods like 'addEmail' to add several mails before sending, and later
> on,
> > when it is called 'send', we can send them in one SMTP connection. Does
> it
> > useful? Thank you all.
> >
> > Hao Zheng
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Re: about sending several emails in a batch

Posted by Siegfried Goeschl <si...@it20one.at>.
Hi,

I have two thoughts along the line

+) using the Commons Email API you get access to the underlying 
MimeMessage which is pretty much the "clean bean email" you are looking for
+) the fact that a Email can send itself is "inversion of control" but 
the bad one - using some sort of transport layer based on interfaces 
would be nice

Cheers,

Siegfried Goeschl

zheng hao wrote:
> hi all Commons Email dev,
>
> I found when i want to send several emails in one connection, Commons Email
> doesn't help. It connects to the SMTP server per email, and it spends more
> time on authentication than sending the mails themselve (most SMTP server
> needs authentication). So I have to code on the javamail api directly,
> something like:
>
>         SMTPSSLTransport strans = (SMTPSSLTransport) sess.getTransport();
>         strans.connect();
>         int num = 1000;
>         for (int i = 0; i < num; i++) {
>             SMTPMessage email = createMessage(sess, num);
>             strans.sendMessage(email, email.getAllRecipients());
>         }
>         strans.close();
>
> In my straightforward test, it saves me 2/3 of the time. So I think it would
> be nice to add this kind of function into Commons Email, to make it more
> useful. My suggestion is to extract a clean bean Email, which contains all
> email dependent information, e.g. TO, CC, Subject, etc, but leaves out all
> host/server dependent information, e.g. authenticator, host address, host
> port, etc. After that, we can still provide simple convenience method for
> those who only want to send one mail every time. And it is possible to add
> methods like 'addEmail' to add several mails before sending, and later on,
> when it is called 'send', we can send them in one SMTP connection. Does it
> useful? Thank you all.
>
> Hao Zheng
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org