Sending Email thorugh MATLAB

Electronic mail or E-mail is around us since 1993. The pioneer of this mode of communication was no doubt 'Hotmail' which is now owned by Microsoft. From computer based application, they have taken it to web and publicize it to an extent that today the official communication seems incomplete without it. Although the first of the web email was sent through a CERN project.
Sending Email thorugh MATLAB
Sending Email thorugh MATLAB
In this MATLAB code I have used MATLAB JAVA classes to use their SMTP access property. For more about EMAIL and SMTP or other protocols which is used to send mails please refer web.

The MATLAB is commented well, but if you have any doubt please comment below. MATLAB code in bold for better contrast from the comments.

%%MATLAB Code for Sending Email %%

clc;close all;clear all;
mail_to=''; %replace with your choice of mail id

%set service='yahoo' for
%set service='gmail' for
%set service='live'  for
%set service='outlook' for
%set service='anyother' for

%set ext='.com' for .com domain
%set ext='.in' for .in domain
%set ext='' for domain
%set ext='.mobi' for .mobi domain
%set ext='.xyz' for .xyz domain

user_name='vibhutesh1494'; %replace the string with your user name

password='xyz'; %replace the string with your password (sender's password)

subject='Anything you want'; %replace the string with subject of your mail
%if you want subject be blank simply make subject=''

body='Type you email content here'; %replace it with content of your mail
%if you want to send a blank mail simply make body=''

attachment='Provide full path of the file to be attached';
%if you dont want to attach anything simply replace attachment='Path' by attachment=[]

%setting up email server by using java classes
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.socketFactory.class', '');

%Change this to port 25, 465, 587, 995 based on server properties
%port 25 for smtp
%port 465 for secured/encrypted smtp
%port 587 for TLS enabled servers
%port 995 for SSL/TLS encrypted POP

switch service
    % add in different cases based on server settings
    case 'gmail'
        id = [user_name,''];
    case 'live'
        id = [user_name,''];
    case 'outlook'
        id = [user_name,''];
    case 'yahoo'
        id = [user_name,''];
        id = [user_name,'@',service,'.com'];

%for login through your smtp settings


*Your mail could end up in SPAM folder particularly if you end up using port 25, so be sure to check this folder too.

*You must be connected to internet for using this code.

*For Gmail it is required to have a secure connection by default. If you get a security certificate error try fiddling up something in your GMAIL account setting to make the mailing transaction unsecured. (At-least for this program).