Skip to Main Content Skip to Search
Product Documentation

sendmail - Send email message to address list

Syntax

sendmail(recipients,subject)
sendmail(recipients,subject,message)
sendmail(recipients,subject,message,attachments)

Description

sendmail(recipients,subject) sends email to recipients with the specified subject. The recipients input is a string for a single address, or a cell array of strings for multiple addresses.

sendmail(recipients,subject,message) includes the specified message. If message is a string, sendmail automatically wraps text at 75 characters. To force a line break in the message text, use 10, as shown in the Examples. If message is a cell array of strings, each cell represents a new line of text.

sendmail(recipients,subject,message,attachments) attaches the files listed in the string or cell array attachments.

Tips

Examples

Send a message with two attachments to a hypothetical email address:

sendmail('user@otherdomain.com',...
         'Test subject','Test message',...
         {'folder/attach1.html','attach2.doc'});
 

Send a message with forced line breaks (using 10) to a hypothetical email address:

sendmail('user@otherdomain.com','New subject', ...
        ['Line1 of message' 10 'Line2 of message' 10 ...
         'Line3 of message' 10 'Line4 of message']);

The resulting message is:

Line1 of message
Line2 of message
Line3 of message
Line4 of message
 

Gmail™ servers require authentication and an encrypted connection (SSL) on port 465. Change your system settings to use your Gmail server and send a test message to your Gmail account:

% Modify these two lines to reflect
% your account and password.
myaddress = 'myaddress@gmail.com';
mypassword = 'mypassword';

setpref('Internet','E_mail',myaddress);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',myaddress);
setpref('Internet','SMTP_Password',mypassword);

props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', ...
                  'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');

sendmail(myaddress, 'Gmail Test', 'This is a test message.');

Alternatives

On Windows systems with Microsoft Outlook®, you can send email directly through Outlook by accessing the COM server with actxserver. For an example, see Solution 1-RTY6J.

See Also

getpref | setpref

How To

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS