How to use mailto: links to send attachments?

Modified on Mon, 14 May, 2018 at 11:54 AM

ImportantOn Android CSS is not supported, so best practise is not to style the email body, and only use HTML tags.


With mailto it is also possible to send attachments.


There are 2 options to achieve this.


Option 1: mailto using an email.config file

This requires an email.config file in JSON format as shown in the following example: 

 

{ "type":"ecfg", 
   "version":"1", 
   "email_subject" : "Requested documents", 
   "email_body" : "", 
   "email_body_file" : "email/email_body.html", 
   "email_attachments": [{
     "path": "email/ClinicalStudy.pdf",
     "mime_type": "application/pdf"
   }]

}

"_comment": "Copyright (c) 2018 The Interact Technology Group. THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. All rights reserved.",

 

With the ‘email_body_file’ key a html file can be specified to use for the email body.


NOTE: The path to the ‘email_body_file’ and attachments is relative to the ‘content’ folder of the asset as shown in the following graphic.




The next step is to code the mailto link to refer to the email.config file within the index.html file:

 

<a target="_blank" href="mailto:[email protected][email protected]&amp;amp;amp;amp;amp;[email protected]&amp;amp;amp;amp;amp;subject=Shipping%20Information%20Request&amp;amp;amp;amp;amp;body=Please%20tell%20me%20if%20my%20order%20has%20shipped!&amp;amp;amp;amp;amp;ni_email_cfg_file=email/email.config">Example link</a>

<!-- Copyright (c) 2018 The Interact Technology Group.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All rights reserved. -->

 

Again, the path to the the email.config file is relative to the ‘content’ folder of the asset


Option 2: mailto using base64 encoded JSON

This requires code in JSON format as shown in the following example: 


{ "type":"ecfg", 
  "version":"1", 
  "email_to" : "[email protected]", 
  "email_cc" : ["[email protected]", "[email protected]"], 
  "email_bcc" : ["[email protected]"], 
  "email_subject" : "Requested documents", 
  "email_body" : "<html><body>Text</body></html>", 
  "email_attachments" : [{ 
    "path" : "email/ClinicalStudy.pdf", 
    "mime_type" : "application/pdf" }]
}

"_comment": "Copyright (c) 2018 The Interact Technology Group. THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. All rights reserved.",


Use an online tool that encodes JSON to base64. Search the internet by using the following string "JSON to base64".


Encode all of the JSON code to base64. This will return a long string e.g. ‘ub2xvZ3kiXSwNCg...’ that can be incorporated in the mailto tag.  


<a target="_blank" href="mailto:[email protected][email protected]&amp;amp;amp;amp;[email protected]&amp;amp;amp;amp;subject=Requested%20documents&amp;amp;amp;amp;ni_email_cfg_base64json=ub2xvZ3kiXSwNCg">Example link</a>

<!-- Copyright (c) 2018 The Interact Technology Group.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
All rights reserved. -->

 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article