How to Open an Email Client with PeopleCode

When there’s an email id displayed on a page, wouldn’t it be cool for your users to be able click on it and have their email client (like Microsoft Outlook) open up a blank mail with the email id and subject line filled in?

Email link on Page

If you have your email client configured, try clicking the link below and you will know what I’m talking about. In this post I’ll cover three ways of doing this on a PeopleSoft page.

Click me to Email

Email open in Outlook

Using a Button

The simplest way to do this is to place a button on the page and change it to a hyperlink. In the FieldChange of the underlying field, use viewcontenturl() as shown below.

&sEmail = "mailto:someone@example.com?Subject=Hello";
ViewContentURL(&sEmail);

However, doing it this way has a drawback – the viewcontenturl function opens a new browser window which in turn invokes the email client.
And this window stays open till manually closed.

A bit annoying for the users? Might be.

So let’s explore another method.

Using an HTML Area

Place an HTML Area on to your page and assign the email link to it as shown below. When you click the link, it will directly invoke the email client.

&sEmailLink = "<a href='mailto:someone@example.com?Subject=Hello' target='_top'> Send Mail</a>";
GK_EMAIL_WRK.HTMLAREA.Value = &sEmailLink;

HTML Area placed on Page

Using an HTML object + HTML Area

Let me bring in some reusability to this and make it look clean in the process. I will use an HTML object to construct the email link here.

Let’s create an HTML object (GK_EMAIL_LINK) and add the below HTML to it.

<a href='mailto:%Bind(:1)?Subject=%Bind(:2)' target='_top'> %Bind(:1) </a>

Now, like I did in the previous method, place an HTML area on the page. The only change would be the way in which I generate the email link.

&sEmailLink = GetHTMLText(HTML.GK_EMAIL_LINK, "someone@example.com", "Hello");
GK_EMAIL_WRK.HTMLAREA.Value = &sEmailLink;

Conclusion

If you notice that your users often copy an email id into their mailing client, it would be a nice idea to use one of these methods to save them some time and improve their experience with PeopleSoft.

Have you done something simple like this that could improve the user’s experience? Let me know through comments.

Subscribe to Comments RSS Feed in this post
3 Responses
  1. It so easy and good to create e mail id

    • Is the mail actually sent?

  2. Hi Rakesh,

    Thanks for the post. I try to practice on that. I have a simple page with a EMPLID and EMAIL. when I click the email outlook is launch and send to and subject is auto populated using your code and I change the send to to my email address and write something to the body and send. Then I close outlook. But I waited for hours but the email was not sent. check junk and trash folder and nothing in there.

    Appreciate your assistance.

    Best Regards,
    Uri

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*