Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email window with recipients without clicking

Status
Not open for further replies.

OsakaWebbie

Programmer
Feb 11, 2003
628
JP
In a dynamic page that is the response to a form submission, I want to both present a page of information and launch an email window with a list of recipients in either TO or BCC. I can build into the page any combination of HTML and Javascript I want (I'm using PHP on the back end, accessing a database), but I can't figure out how to do the email window. With simple HTML I can make a link that will launch the window when clicked on, with the list in the TO field (if the list is not too long for a URL, which it might be in some cases), but (a) I don't want to have to click on it, (b) I don't know how to put the addresses in BCC instead of TO, and (c) I might need a method that allows more than IE's 2086 character limit on URLs. But at a minimum, the question I think is most likely answered by Javascript is (a) - how to make a link do its thing without a human clicking on it, or an alternate way to invoke an email window without a link at all. I searched and searched, but couldn't get the right combination of search criteria to find the answer. Thanks in advance!
 
Hi

OsakaWebbie said:
(a) I don't want to have to click on it,
But that would be the user friendly way.
Code:
window.onload=function(){ location.href='mailto:user@example.com' }
OsakaWebbie said:
(b) I don't know how to put the addresses in BCC instead of TO
Code:
window.onload=function(){ location.href='mailto:user@example.com&CC=someone@example.net&BCC=other@example.org' }
OsakaWebbie said:
(c) I might need a method that allows more than IE's 2086 character limit on URLs
While the [tt]mailto:[/tt] is handled locally, only the browser would set limit for it. And I would say, they have no reason to cut a pseudo-URL handled locally.

Feherke.
 
The amount of data passed in the URL is limited, but I believe it depends on your mail client (although it might be a browser thing).

Depending on your mail client, you might script an ActiveX control to do this. I know that Outlook & Notes can be scripted like this, so it might be your only way.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Another way, depending on your requirements, is doing it server-side.

Cheers,
Dian
 
Thanks for the replies, especially feherke's almost immediate and thorough one. I had seen window.location suggested for someone else on a similar issue, but I assumed the HTML window would be replaced. I see now that it doesn't - nice.

But the email fields don't seem to work right if there is more than one address. I tried separating the addresses with a semicolon, a semicolon plus a space, additionally surrounding the addresses with < >, and doing a separate "&bcc=user@example.com" for each one (something I found someone else suggesting on the internet, but it didn't change anything). Everything after the word "mailto:" all shows up in the TO line of the email, as is (including the "&BCC=etc."), and in some instances I get an additional bizarre insertion of a quotation mark between the first username and its @ character. I'm testing using Thunderbird, if it matters, but I need this to work with at least Thunderbird and Outlook, and it would be good if it worked with Outlook Express as well. (It is a somewhat closed system - it's part of a password-protected database application that I manage.) Here is one example of what was happening - this example is based on feherke's syntax with semicolon separators:
Code:
window.onload=function(){ location.href='mailto:me@here.org&BCC=user1@compuserve.com; user2@yahoo.com;' }
In my email software, the following shows up in TO, and nothing anywhere else:
Code:
me"@here.org&BCC=user1@compuserve.com;user2@yahoo.com;

To respond to other comments:
feherke said:
But that would be the user friendly way.
Not in this case - the user just clicked a button to tell the system to make the email, so making him then click a link on the next page as well would not be user-friendly.
BillyRayPreachersSon said:
Depending on your mail client, you might script an ActiveX control to do this. I know that Outlook & Notes can be scripted like this, so it might be your only way.
I don't have the tools to compile an ActiveX component (or the time to learn another programming language), and even if I did, I suspect it would be specific to a given email client. Anyway, if I can overcome everything except a length limit, I can live with that (for example, I could count characters as I build the string, and if necessary, break the list into pieces to make multiple email windows and let the user combine them).
Diancecht said:
Another way, depending on your requirements, is doing it server-side.
The user hasn't written the email content yet, so server-side isn't an option, I don't think - as far as I know I can't pop up a window in the user's email client from the server side, but can only send a mail directly. The users just want me to populate the recipient fields from the database and let them take it from there.

The user who currently most needs this feature has up to now used a text output feature to get a newline-delimited list of the addresses and copy/pasted into an already open Outlook window. I'm just trying to improve on that, including checking for malformed addresses, duplicates, etc.
 
Hi

You know, I just answered to your question. But I would never in this life do such thing.

I would go with Dian's suggestion of solving it on server-side. Just face the visitor with a [tt]textarea[/tt] where he enters the message body and after submitting it to the server you send it to the addresses you already have.

This way you not expose the mail addresses to the spam bots.

Feherke.
 
BillyRayPreachersSon said:
You're putting spaces and other characters in the URL without encoding them. You need to encode your URL - use the JS "escape" function to do this.
When I ran the whole URL through escape(), it put a slash in front of "mailto", which sent it to a confused HTTP server. When I put only the part after "mailto:" through it, it resulted in the same behavior as without it - all the junk is still just lined up in one TO line. Any more thoughts?

feherke said:
I would go with Dian's suggestion of solving it on server-side. Just face the visitor with a textarea...
Thanks for the editorial comment, but you don't know the circumstances. This needs to get to the user's email client - they might use HTML in their email, attach files (in fact, file attachment is a main one that my husband is using this for every week), etc. It's not for random "visitors", but a select few trained users that I permit to have login privileges. No spambots will get anywhere near it, and even if a hacker got into the database, this functionality does not change the amount of exposure to email addresses - it just adds a new way that the same data can be presented.
 
No problem. [thumbsup2]

Any thoughts on the issue of multiple addresses? Originally I was worried about whether 100 addresses would exceed some limit, but at the moment I would be happy to see it handle 2 correctly...[banghead]
 
Hi

Well, comma ( , ) works for me.
Code:
window.onload=function(){
location.href=
'mailto:user@example.com,someone@example.net,other@example.org'+
'&CC=user@example.com,someone@example.net,other@example.org'+
'&BCC=user@example.com,someone@example.net,other@example.org'
}

Feherke.
 
Thanks - changing to a comma seems to have solved part of the problem. But the "&BCC=" part is still being ignored, both in Thunderbird and Outlook. Here is what my code is doing with a couple test records:
JavaScript:
window.onload=function(){ location.href='mailto:'+escape('myself@mydomain.org&bcc=user2@compuserve.com,user1@domain.com') }
And what I see now in Thunderbird is the following - it recognizes the third address as separate, but the strange quotation mark and "&BCC=" are still just written instead of interpreted:
Code:
TO: myself"@mydomain.org&bcc=user2@compuserve.com
TO: user1@domain.com
In Outlook the response was basically the same, except that the quotation mark did not appear in the first address (also, it changed the comma into a semicolon+space, I guess for its own internal syntax):
Code:
TO: myself@mydomain.org&bcc=user2@compuserve.com; user1@domain.com
Why is it working for you but not me? What email client are you using?

BillyRayPreachersSon said:
"escape" won't add slashes to your string unless you're doing something wrong...
Okay, so I probably did something wrong the first time I tried to use it (I included the "mailto:" in the function parameter, whereas now it's outside it). You can check my usage above and correct me if I'm still not understanding how to use it. But I really don't see any characters in my URL that are getting mangled anyway (interpreted when they should be just passed along) - behavior before and after adding the escape function was the same. I'm having the opposite problem: special strings that I want interpreted but aren't.
 
Your usage of "escape" is fine... but you've removed the spaces from your string which is why you're not seeing the need to use it.

However, I'd still leave it in there.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
The reason you saw spaces in my first posted example was because I started out with only semicolons, but then some other page on the internet said there had to be spaces after the semicolons, so I tried it but it didn't help. The spaces were still in my code when I posted here.
 
Sorry if I missed something, I'll admit to quickly scanning the posts here.

But surely if you are sending mail to 100+ addresses by adding them to the BCC field of a mail and attaching files you are almost certainly going make spam filters flip out.

I too, think that you should do this server side. It will mean more work, but all the things you describe can be done that way. You will also be able to send individual emails rather than a single bulk one.

Maybe the BCC field will cause the mail client to send 100 separate emails but I am not sure of that.

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
Foamcow said:
But surely if you are sending mail to 100+ addresses by adding them to the BCC field of a mail and attaching files you are almost certainly going make spam filters flip out.
I've occasionally heard other people say that more than about ten addresses in BCC makes spam filters unhappy, but with my limited understanding of mail headers, that baffles me - how does a recipient's spam filter know how many other addresses were in the BCC field? My SMTP server is not refusing to send the mail, and after that, I wouldn't think it would matter, except for people who choose to refuse any mail at all that doesn't have their address in the TO field - people who have that stiff a restriction would have to have a "white list" to accomodate most things they want to subscribe to, so we would be already on their white list.

We're already sending mail out to mailing lists in this fashion, using BCC (I refuse to use TO for large lists - I'd rather wrangle with spam filters than spambots!). The only difference is that I want to make it easier to get the addresses from the database to the email client.

Foamcow said:
I too, think that you should do this server side. It will mean more work, but all the things you describe can be done that way.
I'm a fan of server-side - I have done a lot in PHP and love it (I'm not as good in Perl, but I can use it when I have to). But I don't see how this could work that way. The users (primarily my husband so far for this particular feature, but that could change) want to write the mail in their email client, for a variety of reasons. If I write something like mailing list functionality, where he would send his message to some special address that would resend it to multiple recipients, the list would have to be semi-static. On the other hand, my database interface's "multi-select" screen allows a user to choose people from the database on the fly, and then do any of a variety of operations on them, like record attendance of an event, print addresses on envelopes, make plain text or formatted lists of data, and several other things. Currently, to write an email to a "multi-selected" list of people (usually not very many, but sometimes it can be more), my husband uses the text list feature to get the addresses and then pastes them into Outlook. Because he sends the email from a mail client, he has a record of the email and exactly who he sent it to. Do you really think we can have all this functionality server-side?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top