sendmail works when I run my app but not when another user uses it in a packaged app
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
Hello,
I made an app in app designer and part of the app asks the user to input their e-mail address and then the app sends them a "report" of sorts at the end of using the app when they push a "submit" button. The code I write is below.
The issue here is that when I push the submit button, it works and sends me the e-mail. When I sent it out to a friend to test drive, it gave them a "ding" and didn't send the e-mail. Is there anything not packaged up with the app when you create a standalone desktop app that might prevent that functionality?
data={1:10}
out_email=input('email','type the recipient email');
filename=['testing.xlsx'];
filepath=[cd '\' filename];
writecell(data,filepath);
user = getenv('username');
mail = 'myemail@gmail.com'; %my ghost GMail email address
password = 'mypassword'; % ghost GMail password
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail',mail);
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');
sendmail(out_email{:},'Results',{'testing'},filepath)
delete(filepath) %I don't want the user to necesarrily have a copy of the file stored for them - only sent to the provided email
Looking forward to suggestions/thoughts.
Thanks
Accepted Answer
Walter Roberson
on 12 Sep 2020
They probably need to enable gmail "Less Secure Apps" in order for MATLAB to send to gmail .
16 Comments
Shae Morgan
on 12 Sep 2020
I looked into that and my understanding is that setting has to be adjusted for the senders e-mail address, not the recipient.
Other thoughts?
Walter Roberson
on 12 Sep 2020
Hmmm, that's a good point.
Mario Malic
on 13 Sep 2020
It says that the sender needs to disable 2FA if you want to use Less Secure Apps. That's a bit of a hassle just to send an mail.
I am actually curious about this. Maybe you can set up the mail for the task and send the files to yourself (or the same mail, which is a tiny bit insecure if users can see the password for the mail), this way users don't need to fill their user data to some "unknown" script.
Shae Morgan
on 13 Sep 2020
So I made a ghost email account - not my main - so I don’t need to worry so much about the security issues and then allowed the less secure app access. I don’t plan on ever receiving anything to that email - just for sending results to users.
The use for the app by its nature requires me to allow users to specify where they want to send the results without being able to see them (ie, students sending responses to their instructor).
Mario Malic
on 13 Sep 2020
Edited: Mario Malic
on 13 Sep 2020
I see, that comment was a bit misleading for me
%my GMail email address
%Your GMail password
Shae Morgan
on 13 Sep 2020
Apologies - updated the comments
Mario Malic
on 13 Sep 2020
Edited: Mario Malic
on 13 Sep 2020
What about filepath?
filepath=[cd '\' filename];
sendmail('usere-mail@gmail.com','Results',{'testing'},filepath)
I didn't see that one gets confirmation if the mail was sent or not, so maybe it's the attachment problem, maybe cd returns totally different directory than expected.
Or java doesn't get packaged when you create standaloneapp.
Shae Morgan
on 13 Sep 2020
Filepath shouldn’t be the problem I think. Whatever the directory is, it should save the file there and then delete the file after sending the email. I wonder what the CD is for someone using the app from their desktop... I’ll look into it.
I was curious about the java dependencies being included in the package... anyone know about this?
@Mario Malic
The
cd
from an installed app without MATLAB on the computer is the location where the program was run. That's the folder where you installed the program, or the desktop if you made a shortcut. So it seems like this isn't the issue. The filepath is sound.
Any idea if the java dependencies are included included in the package?
Mario Malic
on 14 Sep 2020
Edited: Mario Malic
on 14 Sep 2020
Disclaimer, I have never used mcc.
You can check here for more information link and look in Manage Support Packages and Customize an Application.
EDIT:
This might be useful
Adam Danz
on 14 Sep 2020
Only the sender email needs to change setttings to be less secure.
I have the same setup where a "ghost" email address on gmail was set up solely to send emails from Matlab. I have analyses that take days to complete and they send me an email when they are done.
I've written instructions how to set this up here:
Shae Morgan
on 14 Sep 2020
Edited: Shae Morgan
on 14 Sep 2020
@Adam Danz
The e-mails work beautifully when I run the program myself (following guidance from your linked post above) - but when I packaged it using MATLAB Compiler, and gave it to a non-MATLAB user, they reported hearing a "ding" when they tried to generate the e-mail (which I assume is an error), and no e-mail was sent.
The only explanation I have for now is that that individual doesn't have java on their machine EDIT: and that MATLAB doesn't package java dependencies needed for sendmail in the packaging process using compiler:
I added a few lines of code the give an error mesage if java isn't detected
if ~usejava('jvm')
error('MATLAB:sendmail:NoJvm','SENDMAIL requires Java. File saved to selected desktop directory');
else
%sendmail code recommended above by Adam Danz
end
So I'll see if it still gives the error with that, or if that settles it that code requiring java may not work in packaged apps on machines without java installed.
Shae Morgan
on 14 Sep 2020
Everyone - thanks for the contributions.
Matlab compiler does include a version of JVM that will allow the sendmail function to work. The error received by the beta tester was unrelated to this issue and had to do with permissions on the machine - not a limitation we went into here.
All in all this is solved now and working just fine.
Adam Danz
on 14 Sep 2020
Nearly all of the sendemail errors I've seen are either from incorrect syntax/inputs or with software on local machines that are blocking it (which is usually a good thing). Thanks for letting us know what the probem was, Shae.
@Adam Danz @Walter Roberson
Sending the e-mail works now on windows machines, but not on MAC. I've compiled the app for mac, but when users install the program, it gets hung up on the line of code where you set preferences:
setpref('Internet','SMTP_Server','smtp.gmail.com');
Any idea if the name of preference information is different on a OS X compared to PC?
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)