cant send an email without 'to' on cc or bcc

2,241 views
Skip to first unread message

GX

unread,
Feb 4, 2011, 10:35:37 AM2/4/11
to Railo
Hi All

If you try to send an email with no to field (only cc) railo gives an
exception:

you have do define the to for the mail
at railo.runtime.net.smtp.SMTPClient._send(SMTPClient.java:737):737
at railo.runtime.net.smtp.SMTPClient.send(SMTPClient.java:668):668
at railo.runtime.tag.Mail.doEndTag(Mail.java:515):515
at emailsender_cfc$cf.udfCall(EmailSender.cfc:110):110

indecently it should read "you have to define the 'to' for the mail"

I was wondering why this should be a limitation since one of to, cc or
bcc need only be populated.
I know as a workaround I can use something like to: "undisclosed
recipient", cc: em...@domain.com but was just wondering about the
underlying reason for the restriction/exception.

Regards

GX

GX

unread,
Feb 4, 2011, 10:54:34 AM2/4/11
to ra...@googlegroups.com
hmmm the "undisclosed recipient" trick didnt work..?

this means I have to copy the cc field to the to.. what if there is only bcc? that makes it messy, often when I want to send an email to a group like jokes I bcc all recipients so as if they forward it further down some one doesnt pick up all the addresses for spam.

This can be quite a problem.

GX

Peter Boughton

unread,
Feb 4, 2011, 10:56:35 AM2/4/11
to ra...@googlegroups.com
For a workaround you can set the "to" to the "from" address?

That wont reveal the extra addresses?

GX

unread,
Feb 4, 2011, 2:06:22 PM2/4/11
to ra...@googlegroups.com
yeah but that will send an email to the sender as well wich is not exactly what I want to do

Peter Boughton

unread,
Feb 4, 2011, 2:17:49 PM2/4/11
to ra...@googlegroups.com
It's not a proper solution, but just offering a workaround to the
"undisclosed recipient" not working (because it's not a valid email) -
if you use "undisclosed recipient <sender@domain>" then it will at
least send the email to everyone, and you can possibly use a mailbox
rule to delete the sent one.

Or, maybe try undisclosed@localhost - since that's technically a valid
address it might work, even though the mailbox itself doesn't exist,
and then you don't have to worry about the sender receiving it.

Michael Offner

unread,
Feb 4, 2011, 3:25:33 PM2/4/11
to ra...@googlegroups.com
we look into it, to make it optional (if possible) for railo 3.3, i think this makes sense.

/micha

2011/2/4 GX <mail...@gmail.com>

GX

unread,
Feb 5, 2011, 12:35:04 AM2/5/11
to ra...@googlegroups.com
Thanks Michael

Looks like until then I will have to make the to field mandatory.

p.s. all three 'to', 'cc' and 'bcc' should be optional but at least one of any has to be present

It should be possible because all email systems work that way, however if you telnet a mailserver you need to specify a "MAIL TO:", this however is not necessarily displayed in the headers. Im not sure about what library railo uses to send mail, perhaps the limitation is there.

Regards

GX

Michael Offner

unread,
Feb 7, 2011, 1:26:10 PM2/7/11
to ra...@googlegroups.com
ok, for next ber release of version 3.3, the "to" attribute of tag "cfmail" is now optional.
you can already build a version from git (develop branch).


/micha


2011/2/5 GX <mail...@gmail.com>

GX

unread,
Feb 7, 2011, 11:15:47 PM2/7/11
to Railo
Thanks Michael

On Feb 7, 8:26 pm, Michael Offner <mich...@getrailo.com> wrote:
> ok, for next ber release of version 3.3, the "to" attribute of tag "cfmail"
> is now optional.
> you can already build a version from git (develop branch).
>
> https://issues.jboss.org/browse/RAILO-1176
>
> /micha
>
> 2011/2/5 GX <mailme...@gmail.com>

GX

unread,
Feb 24, 2011, 2:14:49 PM2/24/11
to Railo
Hey guys

Sorry to be digging up this again but I found another issue although
its unrelated see comments below

I have a custom java that has the following code:

// cs is my arbitrary connection settings
javax.mail.Store store = getMailserverSession(cs,
timeout).getStore(cs.protocol.protocol);
store.connect(cs.login, cs.pwd);
store.close();

It works fine from a pure java app but when called from railo it gives
the following:

Message javax.mail.Store.connect(Ljava/lang/String;Ljava/lang/
String;)V
Cause java.lang.NoSuchMethodError

according to java docs:
connect

public void connect(String user, String password) throws
MessagingException

Connect to the current host using the specified username and
password. This method is equivalent to calling the connect(host, user,
password) method with null for the host name.

Parameters:
user - the user name
password - this user's password
Throws:
AuthenticationFailedException - for authentication failures
MessagingException - for other failures
IllegalStateException - if the service is already connected
Since:
JavaMail 1.4

a little digging reveals in railo lib folder a file "sun-mail.jar"
which contains a META-INF that has a: Implementation-Version: 1.3.3_01

Does this mean that the railo mail api is sooo old? This may help the
previous recipient bug.

I know I can remove this jar and use a more updated one but as my
system relies heavily on mail it is a big risk for me.


Regards

GX

On Feb 7, 8:26 pm, Michael Offner <mich...@getrailo.com> wrote:
> ok, for next ber release of version 3.3, the "to" attribute of tag "cfmail"
> is now optional.
> you can already build a version from git (develop branch).
>
> https://issues.jboss.org/browse/RAILO-1176
>
> /micha
>
> 2011/2/5 GX <mailme...@gmail.com>

Michael Offner

unread,
Feb 24, 2011, 2:54:41 PM2/24/11
to ra...@googlegroups.com
We only update jars between major releases, of course you can try to
run Railo with a newer version of the lib.
That "to" was required was no bug, it was a expected behavior and
defined this way in the tld of the tag cfmail. This has nothing to do
with the lib used.

/micha

2011/2/24, GX <mail...@gmail.com>:

GX

unread,
Feb 24, 2011, 4:07:37 PM2/24/11
to Railo
Thanks again Michael

even so java 1.3 is ancient even before railo I assume, I am testing
what you suggested replacing the lib with a newer version but there is
alot to test

GX

On Feb 24, 9:54 pm, Michael Offner <mich...@getrailo.com> wrote:
> We only update jars between major releases, of course you can try to
> run Railo with a newer version of the lib.
> That "to" was required was no bug, it was a expected behavior and
> defined this way in the tld of the tag cfmail. This has nothing to do
> with the lib used.
>
> /micha
>
> 2011/2/24, GX <mailme...@gmail.com>:

Robert Rawlins

unread,
Feb 24, 2011, 5:04:56 PM2/24/11
to ra...@googlegroups.com
Whilst you guys are talking email, thought I might chime in with a quick recommendation for Postmarkapp.com.

It's a nice alternative to SMTP mail, using a JSON based API.

It allows you to very easily track email delivery and bounce backs. We've been putting it into our projects recently and I wouldn't go back, really do recommend it.

I have a ColdBox plugin for it, you'll find a link to it on th PostMark docs, or with a quick search on RIAForge.

I know it's a little OT but thought I'd take the op to spread the word.

I got bored of complications and troubles with SMTP and working with REST feels much more clean and comfortable.

Robert

Sent from my iPhone

Michael Offner

unread,
Feb 25, 2011, 9:39:32 AM2/25/11
to ra...@googlegroups.com
1.3 has nothing to do with 1.3 JRE, this is the version of this lib not java runtime version!
the current version does everything we need, because of that we still use this version, but when you have a need for version 1.4 it is your decision.

/micha



2011/2/24 GX <mail...@gmail.com>

GX

unread,
Feb 28, 2011, 12:29:08 AM2/28/11
to Railo
Hi Michael

Sorry for late reply I missed your post.
Thanks for clarifying that it was a naive assumption.
The problem is that the older railo lib does not handle pop3s and
smtps providers, I keep getting invalid provider.
I did a test after changing the lib and thought everything was working
fine.. but lo and behold... not sending attachments does not work, it
gives an io error.
This leaves me with 2 options, write my own sendEmail function in java
(which will be a pain in the (_)(_) since I need full functionality)
or find a happy medium between the two.

Regards

GX

On Feb 25, 4:39 pm, Michael Offner <mich...@getrailo.com> wrote:
> 1.3 has nothing to do with 1.3 JRE, this is the version of this lib not java
> runtime version!
> the current version does everything we need, because of that we still use
> this version, but when you have a need for version 1.4 it is your decision.
>
> /micha
>
> 2011/2/24 GX <mailme...@gmail.com>

Michael Offner

unread,
Feb 28, 2011, 2:15:27 AM2/28/11
to ra...@googlegroups.com
You can also load the 1.4 with a custom class loader (URLClassLoader)
and then load the classes throw this class loader ( to be sure also
define this class loader as system class loader while using it.
I can do you a little example if you wish.

/micha

2011/2/28, GX <mail...@gmail.com>:

GX

unread,
Feb 28, 2011, 4:22:33 AM2/28/11
to Railo
Hi Michael

Sounds interesting, however I fail to see how this will have two
versions of the same class running in the same jvm. Perhaps an example
as you suggested will help

Regards

GX

On Feb 28, 9:15 am, Michael Offner <mich...@getrailo.com> wrote:
> You can also load the 1.4 with a custom class loader (URLClassLoader)
> and then load the classes throw this class loader ( to be sure also
> define this class loader as system class loader while using it.
> I can do you a little example if you wish.
>
> /micha
>
> 2011/2/28, GX <mailme...@gmail.com>:

GX

unread,
Feb 28, 2011, 4:28:51 AM2/28/11
to Railo
Hi Michael

Ok I think I understand what you are saying, I found this and will
give it a try:
http://blog.getrailo.com/post.cfm/railo-tip-createobject-java

Regards

GX

GX

unread,
Feb 28, 2011, 7:41:01 AM2/28/11
to Railo
Hi Michael

A look at my code reveals this is very complex, I cant tell cfmail
which lib to use (obviously) and in order to do so in my code its
tricky:

I have a method "getConnectionSettings" which is basically a wrapper
of javax.mail.Session.getInstance(prop) as you can see this is a
static function , so I need to find how to use a class loader in java
to get me the version I want.
Unless this version of createobject loads all dependencies of that lib
only (or with higher priority).

I will gave this a try:

<cfset sVars.cJar = expandPath("/../bin/emailfetcher/
emailfetcher.jar") />
<cfset sVars.jCU = createObject("java", "ConnectionUtils",
sVars.cJar) />
<cfset sVars.jS = createObject("java", "javax.mail.Session",
sVars.cJar) />
<cfset sVars.cs = sVars.jCU.getConnectionSettings(arguments.cProvider,
arguments.cPort, arguments.bSsl, arguments.bTls, arguments.cHostname,
arguments.cLogin, arguments.cPwd) />

<cfset sVars.oSession = sVars.jCU.getMailserverSession(sVars.cs,
arguments.nTimeout, true, sVars.jS) />

but unfortunatley it did not work :(
railo.runtime.java.JavaObject cannot be cast to javax.mail.Session

java code:
public ConnectionSettings getConnectionSettings(String protocol,
String port, boolean ssl, boolean tls, String hostname, String login,
String pwd){
return new ConnectionSettings(new Protocol(protocol, port, ssl,
tls), hostname, login, pwd);
}

public javax.mail.Session getMailserverSession(ConnectionSettings c,
int timeout) throws Exception {
return getMailserverSession(c, timeout, false);
}

public javax.mail.Session getMailserverSession(ConnectionSettings c,
int timeout, boolean testPortAndHost) throws Exception {
return getMailserverSession(c, timeout, false, null);
}

public javax.mail.Session getMailserverSession(ConnectionSettings c,
int timeout, boolean testPortAndHost, Object session) throws Exception
{

int port = Integer.parseInt(c.protocol.port);

if(testPortAndHost && !testPortConnection(c.hostname, port,
timeout))
throw new javax.mail.MessagingException("Could not open port");

java.util.Properties prop = new java.util.Properties();
String prot = c.protocol.protocol;
prop.put("mail." + prot + ".connectiontimeout", timeout);
prop.put("mail." + prot + ".timeout", timeout);
prop.put("mail." + prot + ".host", c.hostname);
prop.put("mail." + prot + ".port", port);
if(c.protocol.tls) {
prop.put("mail." + prot + ".starttls.enable", "true");
}
if(c.login.length() > 0) {
prop.put("mail." + prot + ".auth", "true");
prop.put("mail." + prot + ".user", c.login);
if(c.pwd.length() > 0)
prop.put("mail." + prot + ".password", c.pwd);
}

return session == null ? javax.mail.Session.getInstance(prop) :
((javax.mail.Session)session).getInstance(prop);

}

Regards

GX

GX

unread,
Feb 28, 2011, 8:23:11 AM2/28/11
to Railo
I also tried creating an instance of javax.mail.Session directly in
railo:

<cfset sVars.cJar = expandPath("/../bin/emailfetcher/
emailfetcher.jar") />
<cfset sVars.jCU = createObject("java", "ConnectionUtils",
sVars.cJar) />
<cfset sVars.jCS =
sVars.jCU.getConnectionSettings(arguments.cProvider, arguments.cPort,
arguments.bSsl, arguments.bTls, arguments.cHostname, arguments.cLogin,
arguments.cPwd, arguments.nTimeout) />
<cfset sVars.oSession = createObject("java", "javax.mail.Session",
sVars.cJar).getInstance(sVars.jCS.toMailProperties()) />

<cfif arguments.cProvider EQ "smtp" OR arguments.cProvider EQ "smtps">
<cfset sVars.t = sVars.oSession.getTransport(arguments.cProvider) />
<cfset sVars.t.connect(sVars.jCS.login, sVars.jCS.pwd) />
<cfset sVars.t.close() />
<cfelse>
<cfset sVars.store = sVars.oSession.getStore(arguments.cProvider) />
<cfset sVars.store.connect(sVars.jCS.login, sVars.jCS.pwd) />
<cfset sVars.store.close() />
</cfif>

bit this gives No matching Method/Function for
com.sun.mail.smtp.SMTPSSLTransport.CONNECT(string, string) found i.e.
the 1.3 implementation

any other ideas?

GX

GX

unread,
Mar 2, 2011, 12:55:41 AM3/2/11
to Railo
Hi All once again

In order to solve my dilemma I decided to use java to send emails and
am bypassing cfmail tag as well as removing sun-mail.jar and sun-
activation.jar libraries.
I dont like this idea and am sure neither do you but what had to be
done had to be done.

While reading up on mail API I noticed the following change in version
1.4.2 of the mail api:
handle address of the form "Undisclosed-Recipients:;"
found at http://www.oracle.com/technetwork/java/changes-1-150220.txt
so it seems all this fuss brought some light to the original topic :D.

There are many relevant changes but I understand how much of a
headache it is to change such library especially since the only way to
test it is for end users to give feedback.

Thanks again for all your help Michael.

Regards

GX
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages