How do I change the "from" fieild of an email using matlab's "Sendmail"
10 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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.
2 Comments
Julian Hapke
on 16 Mar 2022
If you need special characters as well, you can put in
'"this, contains (stuff)" <from@company.com>'
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!