How do I change the "from" fieild of an email using matlab's "Sendmail"

10 views (last 30 days)
I want to send an email from Matlab but be able to have the full name displayed as the sender. Currently sendmail will just show the name before the "@" as the sender.
Using the example code below, the "from" field is 'displayname' but I want to specify a real persons name with whitespace etc.
username = 'xxx@gmail.com'; %Your GMail email address
password = 'gmailpassword'; %Your GMail password
mail = 'displayname@gmail.com';
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',username);
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');
tic
sendmail('admin@gmail.com',['TESTING (', datestr(now,'dd-mmm-yy') ,')'], ...
'adasdjaldjlajdjalsdkjald');
toc

Answers (1)

Annchen Knodt
Annchen Knodt on 4 Oct 2013
Use the following formatting:
mail = 'Display Name <displayname@gmail.com>';
setpref('Internet','E_mail',mail);
I found that doing so puts "Display Name" as the sender's name and keeps "displayname@gmail.com" as the sender's address / reply-to address.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!