How do I use SENDMAIL to send email from MATLAB 7.2 (R2006a) via the GMail server?
Date Last Modified: Monday, June 20, 2011
| Solution ID: |
|
1-3PRRDV |
| Product: |
|
MATLAB |
| Reported in Release: |
|
R2006b |
| Fixed in Release: |
|
R2011a |
| Platform: |
|
All Platforms |
| Operating System: |
|
All OS |
Subject:
How do I use SENDMAIL to send email from MATLAB 7.2 (R2006a) via the GMail server?
Problem Description:
I would like to send email from MATLAB via the GMail server. If I try to do this using a script such as:
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail','an.example.email.address@gmail.com');
sendmail('an.example.email.address@gmail.com','Test email', 'Test');
I receive the error:
??? Error using ==> sendmail
530 5.7.0 Must issue a STARTTLS command first b19sm1973874ana
Solution:
This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information: To send email using SENDMAIL via the GMail server, you can execute the following in the MATLAB Prompt:
% Define these variables appropriately: mail = 'an.example.email.address@gmail.com'; %Your GMail email address password = 'testing1234'; %Your GMail password
% Then this code will set up the preferences properly: setpref('Internet','E_mail',mail); setpref('Internet','SMTP_Server','smtp.gmail.com'); setpref('Internet','SMTP_Username',mail); setpref('Internet','SMTP_Password',password); 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');
% Send the email. Note that the first input is the address you are sending the email to sendmail('an.example.email.address@gmail.com','Test from MATLAB','Hello! This is a test from MATLAB!')
Note that the above commands are undocumented and may change in future MATLAB releases. Also, note that SENDMAIL does not support servers that require username and password authentications in MATLAB 7.1 (R14SP3) and before and hence the above commands will not work with those releases.
|
Related Solutions: