Page 1 of 1

Generating an email from a screen

Posted: Fri Mar 15, 2013 5:54 pm
by Wayne C.
We are trying to generate an email from by clicking on an email address displayed on a screen. We want to populate the subject with an order # also to be found on the screen. At this stage I've hardcoded something into the subject to get something going. This is what we've come up with after scouring the forums:

pui.link("mailto:"+(get("I_21_8")));pui.link("mailto:?subject=Wayne");

Oddly enough, this actually works sometimes. If it doesn't work and I click on the address again, it may display 2 emails; the first one with the "To:" and "Subject:" populated correctly and a second one with only the "Subject:" populated. We've played with this a bit and can't get it to work correctly on a consistent basis. And I've not even tried to "get" the order # yet. Could somebody help us out?

Re: Generating an email from a screen

Posted: Fri Mar 15, 2013 6:06 pm
by Scott Klement
What you're doing is building a mailto: URI. Similar to an http:// URI, except that it invokes your e-mail client instead of invoking a web page.

You seem to have the idea correct, except that you aren't encoding the URI. There are certain characters that have special meanings ina URI, and so must be encoded (or "escaped") to prevent those special meanings. There's a javaScript function called encodeURIComponent() that is intended for that purpose.

For example:

Code: Select all

pui.link("mailto:president@whitehouse.gov?subject="+encodeURIComponent(get("I_21_8")));
Does that help?

Re: Generating an email from a screen

Posted: Thu Mar 21, 2013 4:36 pm
by Wayne C.
Thanks much Scott. Here's what my final code looks like. Seems to work consistently.

pui.link("mailto:"+encodeURIComponent(get("I_21_8"))+"?subject="+encodeURIComponent(get("D_2_20")));