Share content by mail using service links module

In this blog post you will learn how to create mail share using service links module in Drupal. We are going to create a custom module for this.

sl_mail.info file:

name = Service links mail
description = Service for sharing by mail
dependencies[] = service_links
core = 7.x
package = Service Links - Services

sl_mail.module file:

<?php

/**
 * @file
 * Service for sharing through mail.
 */

/**
 * Implements hook_service_links().
 */
function sl_mail_service_links() {
  $links = array();

  $links['mail'] = array(
    'name' => 'Mail',
    'description' => t('Share this post by mail'),
    'link' => 'mailto:?subject=<encoded-title>&body=<encoded-url>',
    'icon' => drupal_get_path('module', 'sl_mail') .'/mail.png',
    'attributes' => array(
      'class' => array('service-links-mail'),
    ),
  );

  return $links;
}

You will need a mail icon. You can download any mail icon from iconfinder, and save it as mail.png under the module directory, like this sites/all/modules/sl_mail/mail.png.

Enable the module. You have to enable the service from service links settings page here admin/config/services/service-links/services. The new service will look like this service links mail

References: See this documentation of service links module to create custom services.

Updated:

Leave a Comment