Code covered by the BSD License  

Highlights from
gmail

Be the first to rate this file! 16 Downloads (last 30 days) File Size: 2.26 KB File ID: #28919

gmail

by

 

01 Oct 2010 (Updated )

a reasonably secure wrapper for sendmail that configures, and deletes, settings for gmail servers

| Watch this File

File Information
Description

The MATLAB function sendmail will not work with a gmail account without some modification. The problem is that gmail server uses secure authentication and requires a user and password and some changes to the port and SSL settings. The doc page for sendmail (R2010b and later) explains how to do this. Two obvious problems are: (1) the preferences where username and password are saved are persistent between sessions and kept in an unsecure file on your hard drive - a bad idea. (2) the port and SSL setting are not persistent and need to be reset for each MATLAB session - annoying. GMAIL acts as a wrapper to sendmail that sets these values, sends an email, and then erases the user and password values. It is not ultra-secure but at least your password is not saved in a plain text file. Keep in mind though that your password string now exists in the command history! So an optional last argument allows you to delete the command history file after completion. (Note: I don't know how to delete just the last command without a long edit of the file.)

Call for comments: if you can think of another place where the password may be saved after running this function please let me know in the comments. Thanks.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
06 May 2014 Thierry Dalon

Maybe the error
Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection timed out: connect
occurs because we are behind a proxy.
And see http://www.mathworks.de/de/help/matlab/matlab_env/web-browsers-and-matlab.html#bq37bb3-3

01 Nov 2011 Francesco

I also get this error:

Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection refused: connect

I can use the script to send email from my home computer but not from the office. Same Matlab and Windows version. Any idea?

F.

19 Oct 2011 Naor Movshovitz

Chandra, I was unable to reproduce that error. On all machines and configurations I have access to, the emails are sent without a problem. Perhaps there is some setting on your gmail account that prevents outgoing emails from other sources? On my gmail account settings page, under the Forwarding and POP/IMAP tab, I have IMAP enabled. See if that helps.

good luck.

18 Oct 2011 Chandra Kurniawan

??? Error using ==> sendmail at 164
Exception reading response;
Connection reset

Error in ==> gmail at 26
sendmail(recipient,subject,message)

Can U Help me??

20 Jul 2011 Naor Movshovitz

John, I am not getting an error message and my emails are going through same as always. Can you give me a Matlab release and OS that generate the error?

18 Jul 2011 John Fuller

Like other functions of similar purpose I've found, the following error message comes up:

Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection refused: connect

I found this by removing the clc from this function. I'm assuming Gmail has put in some changes that make these no longer functional.

27 Jun 2011 Stan Young

Thank you for the function. It is needed. Are there any functions to retrieve headers or text from IMAP or POP3 servers that anyone is aware of?

16 Oct 2010 Naor Movshovitz

Good catch Gary. Thanks. Revised file uploaded.

15 Oct 2010 Gary

Your regexp to check whether the sender email address is valid does not allow for email addresses with numbers in them.

06 Oct 2010 Naor Movshovitz

That's a good idea. Thank you Jan.

06 Oct 2010 Jan Simon

You can use one of the numerous password input dialogs from the FEX to ask for the password once in a Matlab session. Or you can save the password encrypted with one of the AES function from the FEX. The key for encryption can be stored in a P-coded function, but then additional obfuscation is needed to impede reading the variables with the debugger... At least no clear text password and no history deleting.

Updates
16 Oct 2010

Fixed reg exp check of valid email string to allow numbers and _ and .edu emails.

Contact us