ES

API for sending SMS MailSMS

The API SMS MailSMS is designed for technicians and customers who want to connect their applications with LabsMobile's SMS messaging platform. More information can be found in the MailSMS product description.

The functionality of the SMS MailSMS API is the sending of SMS messages individually via email.

The MaillSMS API is useful in the following cases:

  • No integration possible (proprietary application without access to the code, no technical programming knowledge, etc.)
  • Send an SMS manually from any email client

To start an integration with the MailSMS API, the following requirements are essential:

  • A LabsMobile account associated with a username (registration email). Create an account here.
  • API token used as password and generated from the API Settings section of your account.
  • Format of the email to be sent and explained in this documentation.

RecommendationWe recommend using the API SMS http/POST because it includes more functionality, improves security and performance.


Authentication

In the SMS MailSMS API, authentication is performed with two parameters:

  • The username of the account to be sent in the email as the sender address or From.
  • The tokenapi to be assigned in the subject Subject of the email. This tokenapi can be generated from the API Settings section of your account.

Configuration and filters

The following are important configuration variables and security aspects in an integration with the SMS http/GET API:

  • IP address from which messages will be sent. If this option is enabled, only requests from the list of IP addresses entered will be accepted. This functionality is optional, by default messages will be accepted from any IP.
  • Default sender (default LABSMOBILE). Only some operators allow dynamic, alphanumeric-valued mapping of the sender field.
  • Daily message limit, by default 100,000 sms/day.
  • Message limit per batch, default 10,000 sms/request.
  • Country filter, so that only messages from a list of countries are processed.
  • Anti-duplication filter, to avoid sending identical messages to the same recipient.

All these parameters can be activated and modified in the API Settings and Account Preferences.

Recommendation We recommend activating the Automatic Top-Ups so that there are always credits available in the account and the SMS sending service is not interrupted.


Send SMS MailSMS

To send an SMS through this API you must send an email (e-mail) to an address of the LabsMobile platform. This email will be transformed into an SMS according to the parameters sent.

We recommend checking the Historical of the account for the result and whether the message has been processed correctly or if an error has occurred.

  • PARAMETERS

    Parameters are the common fields of any email that must meet the following requirements:

EMAIL Format
To: XXXXXXXXX@api.labsmobile.com
From: Sender <myUsername>
Subject: <myToken>
Body: <contentMessage>
              
Important

The SMS MailSMS API has some limitations and restrictions such as:

  • Only one SMS can be sent to a single recipient.
  • No response or confirmation of sending.
  • It is not possible to add other parameters such as scheduling, simulated mode, receipt of confirmations, etc.

We recommend if possible the integration with the API SMS http/POST for better security, more functionalities and better performance.

Basic sending
using System;
using System.Net;
using System.Net.Mail;
class SendMailSMS
{
    static void SendMail(string[] args)
    {
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress("myUsernameLabsMobile");
        mailMessage.To.Add("12015550123@api.labsmobile.com");
        mailMessage.Subject = "myTokenLabsMobile";
        mailMessage.Body = "Your verification code is 123";
        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = "addressSmtp";
        smtpClient.Port = 000;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = new NetworkCredential("myUsernameEmail", "myPasswordEmail");
        smtpClient.EnableSsl = true;
        try
        {
            smtpClient.Send(mailMessage);
            Console.WriteLine("Email Sent Successfully.");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }
    }
}
            
package com.example;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

class SendMail {
    public static void main(String[] args) {
      String to = "12015550123@api.labsmobile.com";
      String from = "myUsernameLabsMobile";
      String host = "smtp.com";

      Properties properties = System.getProperties();
      properties.put("mail.smtp.host", host);
      properties.put("mail.smtp.port", "---");
      properties.put("mail.smtp.ssl.enable", "true");
      properties.put("mail.smtp.auth", "true");

      Session session = Session.getInstance(properties, new javax.mail.Authenticator(){
        protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication("myUsernameEmail", "myPasswordEmail");
        }
      });

      try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject("myTokenLabsMobile");
        message.setText("Your verification code is 123");

        Transport.send(message);
      } catch (MessagingException mex) {
        mex.printStackTrace();
      }
   }
}

            
<?php
$to      = '12015550123@api.labsmobile.com';
$subject = 'myToken';
$message = 'Your verification code is 123';
$headers = 'From: myUsername';

mail($to, $subject, $message, $headers);


            
import smtplib
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


sender_email = 'myUsernameLabsMObile'
receiver_email = '12015550123@api.labsmobile.com'
subject = 'myTokenLabsMobile'
message = 'Your verification code is 123'


smtp_server = 'addressSmtp'
smtp_port = 465
username = 'myUsernameEmail'
password = 'myPasswordEmail'

msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = subject

msg.attach(MIMEText(message, 'plain'))

context = ssl.create_default_context()

try:
    with smtplib.SMTP_SSL(smtp_server, smtp_port, context=context) as smtp:
        smtp.login(username, password)
        smtp.send_message(msg)
        print('Email sent successfully.')

except Exception as e:
    print(f'Error: {e}')
            
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'myUsernameEmail',
    pass: 'myPasswordEmail'
  }
});

const mailOptions = {
  from: 'myUsernameLabsMobile',
  to: '12015550123@api.labsmobile.com',
  subject: 'myTokenLabsMobile',
  text: 'Your verification code is 123'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

            
require 'mail'

options = {
  address: 'addressSmtp',
  port: 587,
  domain: 'domail',
  user_name: 'myUsernameEmail',
  password: 'myPasswordEmail',
  authentication: 'plain'
}

Mail.defaults do
  delivery_method :smtp, options
end

Mail.deliver do
  to '12015550123@api.labsmobile.com'
  from 'myUsernameLabsMobile'
  subject 'myTokenLabsMObile'
  body 'Your verification code is 123'
end

puts 'Email sent'
            
Multiple sending
using System;
using System.Net;
using System.Net.Mail;
class SendMailSMS
{
    static void SendMail(string[] args)
    {
        MailMessage mailMessage = new MailMessage();
        mailMessage.From = new MailAddress("myUsernameLabsMobile");
        mailMessage.To.Add("12015550123@api.labsmobile.com");
        mailMessage.To.Add("12015550124@api.labsmobile.com");
        mailMessage.To.Add("12015550125@api.labsmobile.com");
        mailMessage.Subject = "myTokenLabsMobile";
        mailMessage.Body = "Don't miss our Sale! Use code XXXX123 for 20% off.";
        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = "addressSmtp";
        smtpClient.Port = 000;
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = new NetworkCredential("myUsernameEmail", "myPasswordEmail");
        smtpClient.EnableSsl = true;
        try
        {
            smtpClient.Send(mailMessage);
            Console.WriteLine("Email Sent Successfully.");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }
    }
}
            
package com.example;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

class SendMail {
    public static void main(String[] args) {
      String to = {"12015550123@api.labsmobile.com","12015550124@api.labsmobile.com","12015550125@api.labsmobile.com"};
      String from = "myUsernameLabsMobile";
      String host = "smtp.com";

      Properties properties = System.getProperties();
      properties.put("mail.smtp.host", host);
      properties.put("mail.smtp.port", "---");
      properties.put("mail.smtp.ssl.enable", "true");
      properties.put("mail.smtp.auth", "true");

      Session session = Session.getInstance(properties, new javax.mail.Authenticator(){
        protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication("myUsernameEmail", "myPasswordEmail");
        }
      });

      try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setSubject("myTokenLabsMobile");
        message.setText("Don't miss our Sale! Use code XXXX123 for 20% off.");

        Transport.send(message);
      } catch (MessagingException mex) {
        mex.printStackTrace();
      }
   }
}
            
<?php 
$to      = '12015550123@api.labsmobile.com, 12015550124@api.labsmobile.com, 12015550125s@api.labsmobile.com';
$subject = 'myToken';
$message = 'Do not miss our Sale! Use code XXXX123 for 20% off.';
$headers = 'From: myUsername';

mail($to, $subject, $message, $headers);
            
import smtplib
import ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


sender_email = 'myUsernameLabsMObile'
receiver_email = ['12015550123@api.labsmobile.com', '12015550124@api.labsmobile.com', '12015550125@api.labsmobile.com']
subject = 'myTokenLabsMobile'
message = 'Do not miss our Sale! Use code XXXX123 for 20% off.'


smtp_server = 'addressSmtp'
smtp_port = 465
username = 'myUsernameEmail'
password = 'myPasswordEmail'

msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = subject

msg.attach(MIMEText(message, 'plain'))

context = ssl.create_default_context()

try:
    with smtplib.SMTP_SSL(smtp_server, smtp_port, context=context) as smtp:
        smtp.login(username, password)
        smtp.send_message(msg)
        print('Email sent successfully.')

except Exception as e:
    print(f'Error: {e}')
            
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'myUsernameEmail',
    pass: 'myPasswordEmail'
  }
});

const mailOptions = {
  from: 'myUsernameLabsMobile',
  to: '12015550123@api.labsmobile.com,12015550124@api.labsmobile.com,12015550125@api.labsmobile.com',
  subject: 'myTokenLabsMobile',
  text: 'Do not miss our Sale! Use code XXXX123 for 20% off.'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});
            
require 'mail'

options = {
  address: 'addressSmtp',
  port: 587,
  domain: 'domail',
  user_name: 'myUsernameEmail',
  password: 'myPasswordEmail',
  authentication: 'plain'
}

Mail.defaults do
  delivery_method :smtp, options
end

Mail.deliver do
  to '12015550123@api.labsmobile.com,12015550124@api.labsmobile.com,12015550125@api.labsmobile.com',
  from 'myUsernameLabsMobile'
  subject 'myTokenLabsMObile'
  body 'Do not miss our Sale! Use code XXXX123 for 20% off.'
end

puts 'Email sent'