commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Schultz (JIRA)" <j...@apache.org>
Subject [jira] Commented: (EMAIL-72) sending several emails in a batch
Date Mon, 23 Mar 2009 16:29:50 GMT

    [ https://issues.apache.org/jira/browse/EMAIL-72?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12688316#action_12688316
] 

Christopher Schultz commented on EMAIL-72:
------------------------------------------

I'd like to get a discussion going about this bug/enhancement because I'd like to do the same.
Not only does commons-mail not provide batched message support, but it actually hamstrings
you when you try to do it.

I tried to work around o.a.c.m.Email's lack of support for a re-usable Session (Transport,
really) by doing something like this:

Session session = ...;
Transport transport = ...;

Email myEmail = new HtmlEmail();
...

myEmail.buildMimeMessage();
transport.send(myEmail.getMimeMessage());

Unfortunately, buildMimeMessage needs the Session to be set. So, I added:

myEmail.setMailSession(session);

Since I'm using authentication, Email.setMailSession() ignores my request to set the session,
and instead uses its own by calling Session.getInstance. There's even a note in the javadocs
that suggests this might be unexpected:

"
Supply a mail Session object to use. Please note that passing
a username and password (in the case of mail authentication) will
create a new mail session with a DefaultAuthenticator. This is a
convience but might come unexpected.
"

I would argue that it is /not/ a convenience because I can never set a proper Session object
on my messages. The 'session' field is private, so overriding setMailSession is not an option.
The Email class uses the 'session' field directly, so I can't override both setMailSession
/and/ getMailSession to override this behavior.

It appears that there is nothing I can do, here.

Any suggestions?


> sending several emails in a batch
> ---------------------------------
>
>                 Key: EMAIL-72
>                 URL: https://issues.apache.org/jira/browse/EMAIL-72
>             Project: Commons Email
>          Issue Type: New Feature
>         Environment: any
>            Reporter: Hao Zheng
>         Attachments: DemoMailer.java
>
>
> 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 connecting and 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 cleaner Email bean, 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. It's much like the API of javamail
itself, but we can provide more convenient usage than it. Code will look 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();

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message