Follow me on Twitter @AntonioMaio2

Tuesday, December 29, 2015

SharePoint Basics: MailTo Link with New Lines in the Email Body

I was recently asked about how to implement a MailTo link on a SharePoint site page, which is pretty straight forward.  The challenge for the person asking was about how to pre-populate the email body, so that it provided a template for users to fill out when sending that email, and how to have that email body contain multiple lines of text, with carriage returns and new lines between the lines.

There are several methods of doing this which do not work because SharePoint will actually remove the carriage returns and new lines.  There are other methods which do work. 

So, here is a quick post describing one method for accomplishing this.  I'm going to use JavaScript to setup the link so that the script is centralized in one place.

When including carriage returns and new lines in a link, we need to escape those characters so that web browsers can interpret them correctly. 
  • The carriage return is escaped with %0D
  • The new line is escaped with %0A
  • If you want to have text start on one line, then move to the next line, you need to include: %0D%0A
  • If you want to have an empty line between two lines of text, you would simply double the pattern: %0D%0A%0D%0A

In order to create a MailTo link which includes a pre-populated email subject, email addresses and body pre-populated with multiple lines, you can do the following:
  • Create a JavaScript file which contains the following:
Click <a class="email" title="My Link Title" href="#" onclick="javascript:window.location='mailto:emailaddress@company.com?subject=Here Is My Subject Line&body=Here is the start of the email body %0D%0A%0D%0A email body continuing after a new line %0D%0A%0D%0A email body continuing after a second new line %0D%0A%0D%0A email body continuing after a third new line %0D%0A%0D%0A email body continuing after a forth new line %0D%0A%0D%0A email body continuing after a fifth new line.' + window.location;">here</a> to send an email template using a predefined template.

Notice how the link title field, email subject, email addresses and email body are populated.  Notice also how the carriage return and line feed characters are included in the email body.
  • Upload the JavaScript file to the Site Assets SharePoint library
  • On the site page add a Content Editor web part
  • Edit the web part you just added
  • In the Content Link property in the web part editor, add the path to the JavaScript file that you just uploaded to your Site Assets library.
Refresh your page and test your link.

   -Enjoy.

7 comments:

  1. According to this forum, Death is something which is https://topessaybrands.com/review/grademiners-com-review/ for me reality. We can ditch everything but death is something which you never ditch. It is the truth of life. If you want to escape then still you will never be able to escape. YOu can hide at any place but cannot get rid of death.

    ReplyDelete
  2. Very high-quality content and useful information that is very necessary for creating blogs papernow.org and writing term papers and essays can always be obtained using the service because here they can help you with any false task.

    ReplyDelete
  3. Although this is my first visit to your blog, I must say that you have provided me with a wealth of material that is completely new to me. I'm completely enamored with your blogs. I'd want to read more of your posts, but first I need to find an UK Essay Help service to help me write my Essay.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. SEO PowerSuite will offer a gigantic improve to get a website streamlining capabilities.
    https://ryancameron.me

    ReplyDelete
  6. Clearly stated and educational blog Thank you for sharing this article. custom erp developers

    ReplyDelete
  7. The creating a "MailTo Link with New Lines in the Email Body" is a valuable resource for those seeking to enhance their email communication. The step-by-step guide you've provided, along with the insights into the importance of clear and organized email content, is commendable.Similarly, for students seeking clarity and organization in their academic assignments, the expertise of Dissertation Writers can be invaluable. Just as your post emphasizes the need for well-structured emails, these writers ensure that dissertations are meticulously researched, organized, and presented, meeting the highest academic standards.

    ReplyDelete